Re: problem with logoff script

From: Uncle Stewie (whoever_at_whatever.com)
Date: 03/01/04


Date: Mon, 1 Mar 2004 08:18:03 -0600

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

"Rohit Kumar Mehta" <rohitm@nospam.engr.uconn.edu> wrote in message
news:%23xLuvB5$DHA.2036@TK2MSFTNGP12.phx.gbl...
>
> 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



Relevant Pages

  • Re: window object
    ... Within a script, every reference to an object amounts to two ... calls from the scripting engine to the DHTML Object Model. ... var sText = document.all.div1.innerText; ...
    (comp.lang.javascript)
  • Re: Change IP related values due to WAN design change
    ... Unknown network, ... For the cost of testing a dangerous script in a big ... > recurse your text file into an array. ... > var newSettings = new NetworkSettings; ...
    (microsoft.public.windows.server.scripting)
  • Re: Script for adding and deleting rows to a table
    ... that is one long script. ... var numRows = document.getElementById.rows.length; ... //Get Reference to cell that needs to be changed ...
    (comp.lang.javascript)
  • Re: Display a block of text in Firefox & Safari
    ... in FireFox and Safari it appears as a narrow ... There seems to be a needless reliance on the global variable 'NumberOfQuestionsShown', I've suggested a different strategy below that should be easier to maintain - it uses a single class to hide/show questions so the script doesn't need to know how many questions there are nor do they need to be consecutively numbered. ... var questionNum; ... Instead of going through all questions, how about giving them all the same style, then just modify the style to change display from 'none' to ''. ...
    (comp.lang.javascript)
  • Re: Help in checking the OS type...
    ... It lists me out the operating system name thanks for the same. ... I need to develop a script where in i need to first check the type ... Then the Total Space of each ...
    (perl.beginners)