0

I want to use netsh in my app ,the netsh depend some windows server,so i write the bat file ,before i run app i will start these system server

  • bat file
regsvr32.exe /s C:\Windows\system32\Dhcp.dll
regsvr32.exe /s C:\Windows\system32\RpcSs.dll
regsvr32.exe /s C:\Windows\system32\nsi.dll
regsvr32.exe /s C:\Windows\system32\NetTcpPortSharing.dll
regsvr32.exe /s C:\Windows\system32\w32time.dll
regsvr32.exe /s C:\Windows\system32\iphlpsvc.dll

sc config Dhcp start= auto
net start Dhcp
sc config RpcSs start= auto
net start RpcSs
sc config nsi start= auto
net start nsi
sc config NetTcpPortSharing start= auto
net start NetTcpPortSharing
sc config w32time start= auto
net start w32time
sc config iphlpsvc start= auto
net start iphlpsvc
netsh interface portproxy reset
  • golang code
func StartIpHelper() {
    cmd := exec.Command("cmd", "/c", "start_depend.bat")
    if err := cmd.Start(); err != nil {
        logger.Errorln("start depend windows server err:", err)
        return
    }
}

My question

1. in my bat file ,some system server can not run. Maybe my exe do not have Administrator authority

I try this resp ,but not work as win7 and others windows sersiongith

https://github.com/mozey/run-as-admin

2.maybe i run exec.cmd() ,apply Administrator authority

王文杰
  • 26
  • 2
  • [this](https://stackoverflow.com/a/12264592/118109460) might help (provides a way to request elevation within the batch file and works fine when called from go). – Brits Sep 26 '22 at 00:49

0 Answers0