-2

I have this .vbs script :

...
'***************************************************************************************
Sub Ask4Reboot()
Question = MsgBox("Hostname " & DblQuote(strNewName) & " changed after RR" & vbCrLf &_
"Yes - Restart" & vbCrLF &_
"No - STOP Restart" & vbtab & "",VbYesNo+VbQuestion,Title)
If Question = VbYes then 
    Reboot()
Else
    wscript.Quit(1)
End If
End Sub
'**************************************
Function DblQuote(Str)
    DblQuote = chr(34) & Str & chr(34)
End function
'**************************************
Sub Reboot()
Dim ws,Command,Result
Set ws = CreateObject("Wscript.Shell")
Command = "C:\BB\Off.exe "& DblQuote("Restart PC")
Result = ws.run(Command,0,True)
End Sub
'**************************************

How can I change 'Command = shutdown.exe' with C:\BB\Off.exe ; With shutdown.exe command scripts works very well but if I change with Off.exe nothing happend..

edit: *Off.exe works if I just run from cmd.

Thank you.

SySx
  • 51
  • 6
  • Have you tried `Result = ws.run(Command,0,False)`? – LesFerch Apr 14 '22 at 11:33
  • @LesFerch why would not waiting make it better? Does the `off.exe` have a `pause` built in perhaps for a key press? – user692942 Apr 14 '22 at 12:16
  • Also, not a fan of `DblQuote()` function when `"C:\BB\off.exe ""Restart PC"""` would suffice. Escaping quotes isn't difficult just double the quote, there is no need to use the `Chr(34)` approach either. – user692942 Apr 14 '22 at 12:19
  • edit: With 'False' still not working (nothing happend) ; off.exe doens't have an aditional key press. When I run off.exe from cmd ; ATM restarting automatically after the off.exe terminate some process. – SySx Apr 14 '22 at 12:25
  • Where did you get "Off.exe"? Is it part of [this package](https://play.google.com/store/apps/details?id=com.bridgetech.off&hl=en_US&gl=US)? If so, it's Java based and that could be a clue to why it's not working. There are many restart/shutdown exes available for Windows. I suggest trying a different one (stick to open source if possible). – LesFerch Apr 14 '22 at 12:42
  • Unfortunately I need this one: "Off.exe" . This executable stop some services before restart machine. It's works very simple , if i Run off.exe it opens a cmd and begins to stop/close some services after that restart machine and that's all. I can not use shutdown.exe for example because I need to stop some service before restart machines. – SySx Apr 14 '22 at 13:05
  • 1
    You can stop services with the `net` command and then use `shutdown`. – LesFerch Apr 14 '22 at 13:24
  • sure, but, I don't know what/witch service I need to stop. Off.exe I receive from vendor without access in code-source. So in this case i need to implement in my script this 'off.exe' . (exec off.exe and that's all) – SySx Apr 14 '22 at 13:39
  • Well, I looked into downloading this to see if I could replicate your issue, but it's a pay app that was last updated in 2014. No thanks. What functionality of Off.exe do you need? You said "This executable stop some services before restart machine", but that doesn't make sense as a reason to use it. Is it the phone remote control part you need? There are plenty of options on [Google Play](https://play.google.com/store/search?q=shutdown%20pc&c=apps). – LesFerch Apr 15 '22 at 00:30

1 Answers1

-1

You Restart a PC in many ways, here is one.. add below lines to your script

set objShell = wscript.CreateObject("wscript.shell")
objShell.Run "shutdown.exe /R /T 5 /C ""Rebooting"" "

Other ways are here

KrishnaR
  • 344
  • 4
  • 14