powershell如何编程C语言,如何用C语言执行powershell命令
匿名用戶
1級
2015-03-03 回答
我有一條獲取server安裝的各種組件的powershell命令,可以在server上正常命令行執行
powershell -command "& {get-windowsfeature | Out-File -FilePath C:\Command.txt}"
但我用C語言寫出來的exe去跑的時候總是不能正常執行,因為server環境里面沒有debug環境,所以也不知道具體錯在什么地方了,具體source如下:
C/C++ code?
TCHAR szCommandLine[1024] = {0};
sprintf(szCommandLine,
"powershell -command \"& {get-windowsfeature | Out-File -FilePath C:\\Command.txt}\"");
bSuccess = CreateProcess( NULL, // No module name (use command line).
szCommandLine, // Command line.
NULL, // Process handle not inheritable.
NULL, // Thread handle not inheritable.
FALSE, // Set handle inheritance to FALSE.
0, // No creation flags.
NULL, // Use parent's environment block.
NULL, // Use parent's starting directory.
&si, // Pointer to STARTUPINFO structure.
&pi ); // Pointer to PROCESS_INFORMATION structure.
總結
以上是生活随笔為你收集整理的powershell如何编程C语言,如何用C语言执行powershell命令的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 51标准c语言语句范例,51单片机C语言
- 下一篇: c语言继承机制的作用,计算机二级C++强