小编Pet*_*ore的帖子

为什么Powershell Start-Process在从go(golang)调用时不起作用?

我希望在不同的用户下运行Windows批处理脚本,运行go程序的用户.运行go的用户比应该运行批处理脚本的用户拥有更多权限.

从go开始,有几个选项可以在Windows上的不同用户下执行进程,例如使用go中的syscall包直接编写Windows调用.我还没有尝试过这个,但我尝试过使用PsExec和Powershell.Powershell是首选,因为它在Windows 2008 R2上作为标准安装.

以下代码演示了我遇到的问题.在下面的演示中,我运行一个批处理脚本.此批处理脚本直接调用Powershell脚本,然后从go程序中调用它.结果不同.Powershell脚本输出3个文件,但从go调用时,只输出2个文件.

为了完整起见,我还展示了如何创建用户.

C:\计算器\ demo.bat:

::::: create a new user for the demo :::::

:: first create a home directory
mkdir C:\Users\Tom
:: remove Users group
icacls C:\Users\Tom /remove:g Users
:: remove Everyone
icacls C:\Users\Tom /remove:g Everyone
:: create user Tom and set his home directory
net user Tom _Jerry123_ /add /expires:never /passwordchg:no /homedir:C:\Users\Tom /y
:: Give Tom access to his home directory
icacls C:\Users\Tom /grant:r Tom:(CI)F SYSTEM:(CI)F Administrators:(CI)F
:: give him access to Remote Desktop
net …
Run Code Online (Sandbox Code Playgroud)

windows powershell batch-file go

7
推荐指数
1
解决办法
3102
查看次数

标签 统计

batch-file ×1

go ×1

powershell ×1

windows ×1