<p>So i need my program to know if it has admin/elevated rights on the computer, I can't seem to find any method for this in Go anywhere...</p>
<hr/>**评论:**<br/><br/>ericzhill: <pre><p>Go is somewhat platform agnostic, and as such wouldn't come with something this Windows-specific out of the box. You should be able to implement it with the Windows API though. Have a look at this:</p>
<p><a href="http://stackoverflow.com/questions/8046097/how-to-check-if-a-process-has-the-administrative-rights" rel="nofollow">http://stackoverflow.com/questions/8046097/how-to-check-if-a-process-has-the-administrative-rights</a></p></pre>mwholt: <pre><p>One way is to simply try to do what you want to do, and if it fails with a permission error, then you don't have permission to do it.</p></pre>SaturnsVoid: <pre><p>Tried that on a Windows 7 VM, It made a file in VirtualStore and thought it was on the C:\</p></pre>GrayFox89: <pre><p>Have you tried checking environment variables? Could be something useful there.</p>
<p>As someone said, you could try doing an operation that requires admin permissions, like opening <code>\\.\PHYSICALDRIVE0</code> in read-only mode (and just close it).</p></pre>SaturnsVoid: <pre><p>Thanks, i wrote the following function to test it;</p>
<p><a href="https://play.golang.org/p/bBtRZrk4_p" rel="nofollow">https://play.golang.org/p/bBtRZrk4_p</a> (Reddit hates to format code...)</p>
<p>and it seems to work great!</p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
0 回复
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传