Solved

need assistance with a login script that will reboot the system only one time

Posted on 2014-11-25
10
141 Views
Last Modified: 2014-11-25
We are deploying a login script that requires the system be rebooted, however we need a way to add logic to the script so that the system will not reboot as second time.

can someone provide a way that we can add additional logic to copy a file and if the system sees the file, it will know not to reboot a second time.

thanks in advance.

S
0
Comment
Question by:siber1
  • 4
  • 4
  • 2
10 Comments
 
LVL 24

Expert Comment

by:NVIT
ID: 40465645
Is the script a .bat file? How about...
if exist %temp%\DidReboot.txt goto :EOF
(reboot code here)

Open in new window

0
 

Author Comment

by:siber1
ID: 40465654
thx. how would I incorporate that into this script, so that the system does not reboot each time the users logs in:

@echo off
MsiExec.exe /I{8F023021-A7EB-45D3-9269-D65264C81729} /qb
MsiExec.exe /X {786A9F7E-CFEC-451F-B3C4-22EB11550FD8} /q
powershell -executionpolicy bypass -file \\fs1\deploy\fwenable.ps1
gpupdate /force
shutdown.exe /r /t 00

Open in new window

0
 
LVL 29

Expert Comment

by:becraig
ID: 40465657
simply set a scheduled task on the computer to run at startup and to run once.
Step1 The scheduled task
schtasks /create /RU system /SC ONSTART /TN "Reboot Task"
/TR "c:\temp\rebooter.ps1"

Open in new window



maybe a simple one liner script like this (save as ebooter.ps1)

Step2 The script
New-Item -Type file c:\rebooted.txt SchTasks /Delete /TN “Reboot Task”
0
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
LVL 24

Accepted Solution

by:
NVIT earned 500 total points
ID: 40465659
@echo off
MsiExec.exe /I{8F023021-A7EB-45D3-9269-D65264C81729} /qb
MsiExec.exe /X {786A9F7E-CFEC-451F-B3C4-22EB11550FD8} /q
powershell -executionpolicy bypass -file \\fs1\deploy\fwenable.ps1
gpupdate /force

if exist %temp%\DidReboot.txt goto :EOF
shutdown.exe /r /t 00
echo Rebooted %computername% %date% %time%>%temp%\DidReboot.txt

Open in new window

0
 

Author Closing Comment

by:siber1
ID: 40465669
brilliant. just what I was looking for.

many thanks!
0
 
LVL 29

Expert Comment

by:becraig
ID: 40465672
Taking a look at your script, I cannot see any reason not to reboot after the msi install.

The chances of a reboot happening before the msi install is complete seems highly unlikely.


So in this scenario, if the msi is what requires the reboot then no matter if a recent shutdown happened or not it will still need to reboot.
0
 

Author Comment

by:siber1
ID: 40465682
thanks becraig, the issue is, we needed that logic to prevent the system from rebooting every time the user logs in.
0
 
LVL 29

Expert Comment

by:becraig
ID: 40465692
So then instead of checking for the file when the system reboots, check for the presence of whatever it is the msi is installing.

That way you also do not install on every login.

There has to be a way to do that check simply make that your first step and evaluate if it is present and exit if it is, if not then run the msi install and reboot.
0
 

Author Comment

by:siber1
ID: 40465702
ah.. sorry the syntax I provided was slightly off, I should have read /x  [these are uninstall commands only]
good catch :)
0
 
LVL 29

Expert Comment

by:becraig
ID: 40465711
In either event I would still check the presence before the uninstall action.

I am sure you can do so using any number of options based on how the application is actually installed.
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
This article explains how to install and use the NTBackup utility that comes with Windows Server.
how to add IIS SMTP to handle application/Scanner relays into office 365.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question