C ++创建进程PowerShell作为管理员,隐藏,不要等待它
c++ createprocess powershell as admin, hidden and dont wait for it
这就是我所拥有的,在没有命令的情况下启动powershell.exe并在它之后直接关闭。为什么它不起作用?
int main(int argc, char *argv[])
{
[...]
CreateProcess( NULL, // No module name (use command line)
"powershell.exe -command ".C:\test\t.ps1" ",
[...]
&si, // Pointer to STARTUPINFO structure
&pi ); // Pointer to PROCESS_INFORMATION structure
return 0;
}
在普通cmd中,命令如下所示:
powershell -command ".c:testt.ps1"
在文件中,如果要测试它,请
在此单行中:write-host "hello world" |out-file C:testhi.txt
应该在控制台中写 hello world 并在文件夹中创建 hi.txt
命令行应为:
CreateProcess(NULL, // No module name (use command line)
"powershell.exe -command "& {C:\test\t.ps1}"",
或
CreateProcess(NULL, // No module name (use command line)
"powershell.exe -file C:\test\t.ps1",
通常,对于执行脚本,请使用 -File,除非退出代码对您很重要。 如果是,请使用 -Command
,因为 -File 存在一个错误,即使存在错误,它也始终返回 0(成功)。
如果希望执行 powershell.exe 提示提升,请改用 ShellExecute API。 传入"RunAs"
for lpOperation
,您可以使用 nShowCmd
参数指定隐藏窗口。
相关文章:
- 为什么我的C#代码在调用回C++COM直到Task时会暂停.等待/线程.加入
- 这是我尝试让用户将值输入到数组中.然后将其隐藏为大量的星号
- 如何让LLDB在成功时退出,在失败时等待
- 结构和双指针隐藏在其他结构中,多层混淆
- 等待整个 omp 块完成,然后再调用第二个函数
- 在 cpp 文件中隐藏采用模板参数引用的方法
- 提升 ASIO - io_service 不要等待连接到线程
- 如何在C++中实现带有packaged_task的异步等待循环?
- 参数包构造函数在类模板中隐藏用户定义的转换
- 虚假唤醒是否会解锁所有等待线程,甚至是不相关的线程?
- 如何等待窗口隐藏在Qt中?
- 如何使用类型别名从模板化类中隐藏模板列表
- 在设计 SDK 时,我是否应该在 C++ 头文件中完全隐藏内部类?
- 如何在不等待检索的情况下获取C++中的内存位置?
- 等待被迷住了,没有回来
- 等待 WaitForMultipleObjects 窗口中的事件数量可变
- 名称隐藏对静态函数继承的实例使用
- 一个线程等待多个线程事件
- 等待 qthread 终止的正确方法是什么?
- C ++创建进程PowerShell作为管理员,隐藏,不要等待它