马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
x
这里使用了powershell脚本举行操纵,使用golang举行简单的封装,实现平凡用户下安装软件
powershell命令表明
- $securePassword = ConvertTo-SecureString "yourpasswd" -AsPlainText -Force #转换密码为SecureString格式
- $credential = New-Object System.Management.Automation.PSCredential("administrator", $securePassword) #创建PSCredential对象
- $programPath = "C:\PAClient.exe"
- Start-Process -FilePath $programPath -Credential $credential
复制代码- package main
- import (
- "fmt"
- "os/exec"
- )
- func main() {
- // 管理员账号和密码
- username := "Administrator"
- password := "yourpasswd"
- // 要安装的应用程序路径
- programPath := "C:\\PAClient.exe"
- // 创建PowerShell命令字符串
- psCommand := fmt.Sprintf(`
- $securePassword = ConvertTo-SecureString '%s' -AsPlainText -Force;
- $credential = New-Object System.Management.Automation.PSCredential('%s', $securePassword);
- Start-Process -FilePath '%s' -Credential $credential;
- `, password, username, programPath)
- // 执行PowerShell命令
- cmd := exec.Command("powershell", "-Command", psCommand)
- output, err := cmd.CombinedOutput()
- if err != nil {
- fmt.Println("Error executing PowerShell command:", err)
- fmt.Println(string(output))
- return
- }
- fmt.Println("Process installed successfully")
- }
复制代码 免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。 |