Solved

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

Posted on 2014-11-25
10
143 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Windows 10 came with  a lot of built in applications, Some organisations leave them there, some will control them using GPO's. This Article is useful for those who do not want to have any applications in their image (example:me).
This article explains the steps required to use the default Photos screensaver to display branding/corporate images
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

685 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