go+powershell脚本实现预填写管理根据安装软件

农民  论坛元老 | 2024-11-19 02:18:47 | 显示全部楼层 | 阅读模式
打印 上一主题 下一主题

主题 1586|帖子 1586|积分 4758

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

x
这里使用了powershell脚本举行操纵,使用golang举行简单的封装,实现平凡用户下安装软件
powershell命令表明
  1. $securePassword = ConvertTo-SecureString "yourpasswd" -AsPlainText -Force #转换密码为SecureString格式
  2. $credential = New-Object System.Management.Automation.PSCredential("administrator", $securePassword) #创建PSCredential对象
  3. $programPath = "C:\PAClient.exe"
  4. Start-Process -FilePath $programPath -Credential $credential
复制代码
  1. package main
  2. import (
  3.         "fmt"
  4.         "os/exec"
  5. )
  6. func main() {
  7.         // 管理员账号和密码
  8.         username := "Administrator"
  9.         password := "yourpasswd"
  10.         // 要安装的应用程序路径
  11.         programPath := "C:\\PAClient.exe"
  12.         // 创建PowerShell命令字符串
  13.         psCommand := fmt.Sprintf(`
  14.     $securePassword = ConvertTo-SecureString '%s' -AsPlainText -Force;
  15.     $credential = New-Object System.Management.Automation.PSCredential('%s', $securePassword);
  16.     Start-Process -FilePath '%s' -Credential $credential;
  17.     `, password, username, programPath)
  18.         // 执行PowerShell命令
  19.         cmd := exec.Command("powershell", "-Command", psCommand)
  20.         output, err := cmd.CombinedOutput()
  21.         if err != nil {
  22.                 fmt.Println("Error executing PowerShell command:", err)
  23.                 fmt.Println(string(output))
  24.                 return
  25.         }
  26.         fmt.Println("Process installed successfully")
  27. }
复制代码
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

农民

论坛元老
这个人很懒什么都没写!
快速回复 返回顶部 返回列表