Note that the boot mode should be "Automatic" instead of "Auto"
copy code code as follows:
Const own_process = &h10
Const Err_control = &h2
Const INTERACTIVE = False
ServiceName = "Testservice"
DisplayName = "This is a test service."
InstallPath = "C:windowssystem32test.exe"
Set objwmi = GetObject ("winmgmts:" & "{impersonationlevel=impersonate, (Security)}!." Rootcimv2 ")
Set objsvr = Objwmi.get ("Win32_Service")
return = Objsvr.create (ServiceName, DisplayName, InstallPath, Own_ PROCESS, Err_control, "Automatic", INTERACTIVE, "LocalSystem", "")
If (return = 0) Then
wscript.echo "Servic E Create success. "
wscript.echo "ServiceName:" & ServiceName
wscript.echo "DisplayName:" & DisplayName
&N Bsp WScript.Echo "InstallPath:" & InstallPath
wscript.echo "
Else
wscript.echo" Service Create Failure ("& Return &"). "
wscript.quit (return)
End If
Wscript.Quit