problem with logoff script

  • Thread starter Rohit Kumar Mehta
  • Start date
R

Rohit Kumar Mehta

Hello, I am trying to make a group of dual boot Windows 2000
Professional machines reboot after a user logs off of them. (We need
this for the dual boot setup).

The procedure I am trying to use is as follows:

1) Create an OU for the machines in the Active Directory, put the
machines in the OU.
2) Apply a GPO that OU. In the GPO under User Configuration=>Windows
Settings=>Scripts=>Logoff add a script.
3) Set the script to \\dc\netlogon\logoff.bat
4) Copy shutdown.exe from Windows Resource Kit to \\dc\netlogon

I am not sure why this does not work. If I run \\dc\netlogon\logoff.bat
from the commandline it works. And the computer reboots.

When I logoff the first time, I see an error message briefly and it
is difficult to read. This is my best approximation:
MOBYSYNC.EXE - Initialization failed (although after googling I think
this is MOBSYNC.EXE)
the dll failed to initialize because windows is shutting down

I also did another test where I started running logoff.bat (which calls
shutdown.exe). As it began the process of rebooting the system. I
clicked Start=>Logoff. The computer logged my user out, but never
rebooted. Is this a synchronization issue?

Thanks in advance for any suggestions/advice,

Rohit
 
U

Uncle Stewie

I would try something differnet...

Why not use a VBScript, or JScript using WMI to shut down the workstation...
This would be a call to a local API and you would not require an external
executable... When a workstation is shutting down it is terminating services
and disconnecting user network connections... perhaps your batch file is
getting lost in the organized mayhem... a call to a script will kick off
the script engine as a process on the workstation and should execute cleanly
and without issue...

This should help: save this as a JScript file... reboot.js and modify the
code in the Base Code Area

// -----------------------------------------------
// Copyright © 2004 The ATLED Engineering Group
//
// General OS Information Script
//
// By: Stewart C. Basterash
// The ATLED Engineering Group
// 414.702.0987
// On: January 6th, 2003
// ----------------------------------------------

var ado = new ActiveXObject("ADODB.Connection");
var fso = new ActiveXObject("Scripting.FileSystemObject");
var nwo = new ActiveXObject("WScript.Network");
var sho = new ActiveXObject("WScript.Shell");
var wmi = new ActiveXObject("WbemScripting.SWbemLocator");
var wmiNameSpace = 'root\\cimv2'; //"root/CIMV2

curDir = sho.CurrentDirectory;
curDir = curDir.replace(/\\/g, '/');
sysDir = sho.ExpandEnvironmentStrings("%SystemDrive%");
winDir = sho.ExpandEnvironmentStrings("%windir%");
winDir = winDir.replace(/\\/g, '/');

//------------------------------------------------
// Base Code Goes Here

if (getOS(nwo.ComputerName)== 'Win2K'){
sho.popup('Ready to reboot Windows 2000 machine ' + nwo.ComputerName);
// reboot(nwo.ComputerName);
}
if (getOS(nwo.ComputerName)== 'WinXP'){
sho.popup('Ready to reboot Windows XP machine ' + nwo.ComputerName);
// reboot(nwo.ComputerName);
}


//------------------------------------------------



function getOS(name)
{
try {
switch (getOSType(name)) {
case 16: {
return 'Win95'; }
case 17: {
return 'Win98'; }
case 18: {
switch (getOSVersion(name).substr(0,3)) {
case '4.0' : {
return 'WinNT';}
case '5.0' : {
return 'Win2K';}
case '5.1' : {
return 'WinXP';}
case '5.2' : {
return 'Win23';}
default : {
'UnknownNT'; }
} // switch getOSVersion
} // case 18
default : {
return 'Unknown'; }
} // switch getOSType()
} // try
catch (e) {
sho.popup('An error occured attempting to get the Operating System Type.
The error was ' + e.number & 0xFFFF + ' ' + e.description);
return ''; } // catch
}

function reboot(name)
{
try {
var objComputer =
GetObject('winmgmts:{impersonationLevel=impersonate,(Shutdown,
RemoteShutdown)}!\\\\'+name.toUpperCase()+'\\root\\cimv2').ExecQuery('select
* from Win32_OperatingSystem');
var n = new Enumerator(objComputer);
for(;!n.atEnd();n.moveNext()) {
var opSys = n.item();
opSys.Reboot(); } } // try
catch (e) {
sho.popup('An error occured attempting to Reboot computer
'+name.toUpperCase()+'. The error was ' + e.number & 0xFFFF + ' ' +
e.description);
return ''; } // catch
}

function getDateTime(name)
{
try {
var objComputer =
GetObject('winmgmts:{impersonationLevel=impersonate,(SystemTime)}!\\\\'+name
..toUpperCase()+'\\root\\cimv2').ExecQuery('select LocalDateTime from
Win32_OperatingSystem');
var n = new Enumerator(objComputer);
for(;!n.atEnd();n.moveNext()) {
var opSys = n.item();
return opSys.LocalDateTime; } } // try
catch (e) {
sho.popup('An error occured attempting to get the Date Time from
computer '+name.toUpperCase()+'. The error was ' + e.number & 0xFFFF + ' ' +
e.description);
return ''; } // catch
}

function setDateTime(name, value)
{
// value = yyyymmddHHMMSS.mmmmmmsUUU
try {
var objComputer =
GetObject('winmgmts:{impersonationLevel=impersonate,(SystemTime)}!\\\\'+name
..toUpperCase()+'\\root\\cimv2').ExecQuery('select LocalDateTime from
Win32_OperatingSystem');
var n = new Enumerator(objComputer);
for(;!n.atEnd();n.moveNext()) {
var opSys = n.item();
return opSys.SetDateTime(value); } } // try
catch (e) {
sho.popup('An error occured attempting to set the Date Time from
computer '+name.toUpperCase()+'. The error was ' + e.number & 0xFFFF + ' ' +
e.description);
return ''; } // catch
}

function getLoggedOnUser(name)
{
try {
var objComputer =
GetObject('winmgmts:{impersonationLevel=impersonate}!\\\\'+name.toUpperCase(
)+'\\root\\cimv2').ExecQuery('select * from Win32_ComputerSystem');
var n = new Enumerator(objComputer);
for(;!n.atEnd();n.moveNext()) {
var ctr = n.item();
return ctr.UserName.toUpperCase(); } } // try
catch (e) {
sho.popup('An error occured attempting to get the Logged On User from
computer '+name.toUpperCase()+'. The error was ' + e.number & 0xFFFF + ' ' +
e.description);
return ''; } // catch
}

function getOSBuild(name)
{
try {
var objSys =
GetObject('winmgmts:{impersonationLevel=impersonate}!\\\\'+name.toUpperCase(
)+'\\root\\cimv2').ExecQuery('select * from Win32_OperatingSystem');
var n = new Enumerator(objSys);
for(;!n.atEnd();n.moveNext()) {
var sys = n.item();
return sys.BuildNumber; } } //try
catch (e) {
sho.popup('An error occured attempting to get the Operating System
Build. The error was ' + e.number & 0xFFFF + ' ' + e.description);
return ''; } // catch
}

function getOSCaption(name)
{
try {
var objSys =
GetObject('winmgmts:{impersonationLevel=impersonate}!\\\\'+name.toUpperCase(
)+'\\root\\cimv2').ExecQuery('select * from Win32_OperatingSystem');
var n = new Enumerator(objSys);
for(;!n.atEnd();n.moveNext()) {
var sys = n.item();
return sys.Caption; } } // try
catch (e) {
sho.popup('An error occured attempting to get the Operating System
Caption. The error was ' + e.number & 0xFFFF + ' ' + e.description);
return ''; } // catch
}

function getOSType(name)
{
try {
var objSys =
GetObject('winmgmts:{impersonationLevel=impersonate}!\\\\'+name.toUpperCase(
)+'\\root\\cimv2').ExecQuery('select * from Win32_OperatingSystem');
var n = new Enumerator(objSys);
for(;!n.atEnd();n.moveNext()) {
var sys = n.item();
return sys.OSType; } } // try
catch (e) {
sho.popup('An error occured attempting to get the Operating System
Directory. The error was ' + e.number & 0xFFFF + ' ' + e.description);
return ''; } // catch
}

function getOSVersion(name)
{
try {
var objSys =
GetObject('winmgmts:{impersonationLevel=impersonate}!\\\\'+name.toUpperCase(
)+'\\root\\cimv2').ExecQuery('select * from Win32_OperatingSystem');
var n = new Enumerator(objSys);
for(;!n.atEnd();n.moveNext()) {
var sys = n.item();
return sys.Version; } } // try
catch (e) {
sho.popup('An error occured attempting to get the Operating System
Version. The error was ' + e.number & 0xFFFF + ' ' + e.description);
return ''; } // catch
}

function getOSWinDir(name)
{
try {
var objSys =
GetObject('winmgmts:{impersonationLevel=impersonate}!\\\\'+name.toUpperCase(
)+'\\root\\cimv2').ExecQuery('select * from Win32_OperatingSystem');
var n = new Enumerator(objSys);
for(;!n.atEnd();n.moveNext()) {
var sys = n.item();
return sys.WindowsDirectory; } } // try
catch (e) {
sho.popup('An error occured attempting to get the Operating System
Directory. The error was ' + e.number & 0xFFFF + ' ' + e.description);
return '';
} // catch
}

function GetApplication()
// Retrieve the script application
{
try {
return WScript.Application; } // try
catch (e) {
sho.popup('An error occured attempting to get the Application. The error
was ' + e.number & 0xFFFF + ' ' + e.description);
return '';
} // catch
}

function GetScriptName()
// Retrieve the script application
{
try {
return WScript.ScriptName; } // try
catch (e) {
sho.popup('An error occured attempting to get the Script Name. The error
was ' + e.number & 0xFFFF + ' ' + e.description);
return '';
} // catch
}

function GetScriptFullName()
// Retrieve the script application
{
try {
return WScript.ScriptFullName; } // try
catch (e) {
sho.popup('An error occured attempting to get the Script Full Name. The
error was ' + e.number & 0xFFFF + ' ' + e.description);
return '';
} // catch
}

function GetVersion()
// Retrieve the script application
{
try {
return WScript.Version; } // try
catch (e) {
sho.popup('An error occured attempting to get the Script Engine Version.
The error was ' + e.number & 0xFFFF + ' ' + e.description);
return '';
} // catch
}

function GetPath ()
// Retrieve the script path
{
try {
var path = WScript.ScriptFullName;
path = path.substr(0,path.lastIndexOf("\\")+1);
return path; } // try
catch (e) {
sho.popup('An error occured attempting to get the Script Path. The error
was ' + e.number & 0xFFFF + ' ' + e.description);
return '';
} // catch
}

Good Luck
 
R

Rohit Kumar Mehta

Thank you very much for this script. As I have some Java programming
experience, it looks a little less intimidating doorway to the Microsoft
scripting world than VBScript.

However, it still does not solve the problem. Executing this directly
reboots the machine. However, executing it as a Logoff script silently
fails :( I am guessing that this problem is solved with Win2k3
synchronized logoff scripts, but I'm not sure what to do with our Win2K
DC.

Rohit

Uncle said:
I would try something differnet...

Why not use a VBScript, or JScript using WMI to shut down the workstation...
This would be a call to a local API and you would not require an external
executable... When a workstation is shutting down it is terminating services
and disconnecting user network connections... perhaps your batch file is
getting lost in the organized mayhem... a call to a script will kick off
the script engine as a process on the workstation and should execute cleanly
and without issue...

This should help: save this as a JScript file... reboot.js and modify the
code in the Base Code Area
[cut]
 
U

Uncle Stewie

That is odd... I will see what I can find...

There is a caveat to this script (like any other script)... the logged on
user has to have the shutdown right or it will fail (silently)... check the
permissions on the workstation\server in question... in the mean time I will
do some research...

Good Luck

Rohit Kumar Mehta said:
Thank you very much for this script. As I have some Java programming
experience, it looks a little less intimidating doorway to the Microsoft
scripting world than VBScript.

However, it still does not solve the problem. Executing this directly
reboots the machine. However, executing it as a Logoff script silently
fails :( I am guessing that this problem is solved with Win2k3
synchronized logoff scripts, but I'm not sure what to do with our Win2K
DC.

Rohit

Uncle said:
I would try something differnet...

Why not use a VBScript, or JScript using WMI to shut down the workstation...
This would be a call to a local API and you would not require an external
executable... When a workstation is shutting down it is terminating services
and disconnecting user network connections... perhaps your batch file is
getting lost in the organized mayhem... a call to a script will kick off
the script engine as a process on the workstation and should execute cleanly
and without issue...

This should help: save this as a JScript file... reboot.js and modify the
code in the Base Code Area
[cut]
 
R

Rohit Kumar Mehta

Thanks again. The user does have permission to shutdown the
workstation. If I run \\dc\netlogon\reboot.js it works.
However from the logoff script it does not work

I was incorrect in saying it will fail silently. I get a similar
MOBYSYNC.EXE error the first time the logoff script (reboot.js now) is
run. After that it fails silently until I reboot the machine.

While a reboot-on-logoff setup is ideal, we may take a different path
completely (such as disabling logoff and only allowing reboot) or
rebooting every dual boot workstation at 4 AM.

Many thanks,

Rohit
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top