Ghost Solution Suite

 View Only
  • 1.  Problems Executing Command from Ghost Console

    Posted May 02, 2007 03:51 PM

    I'm trying to execute a command using the ghost console. The command is running a .bat file that sets the default printer. I am using this command to set the printer:

    rundll32 printui.dll,PrintUIEntry /y /n "\\printserver\printer"

    When I run this bat file from the machine It goes off without a hitch. However, when I set a Ghost Console task to execute a command that runs this .bat file I get this error message:

    Do you have any ideas why I would be getting this only when running from the Console? What exactly is happening behind the scenes when executing tasks?

    Thanks!



  • 2.  RE: Problems Executing Command from Ghost Console

    Posted May 02, 2007 04:02 PM
    I would suggest using the command without the transfer of the batch file.  If I had to guess I would say its an environment/working directory issue.
     
    Instead of transferring the bat file try just this command:
     
    Command:  c:\windows\system32\rundll32.exe
     
    Arguments: printui.dll,PrintUIEntry /y /n "\\printserver\printer"


  • 3.  RE: Problems Executing Command from Ghost Console

    Posted May 02, 2007 04:43 PM
    Thank you for the response.  I just tried your suggestion but am still receiving the same error.  Any other ideas?
     
    EDIT: I did some additional testing.  I decided to try setting a local printer instead of a network printer.  Now I am not receiving an error message anymore and the .bat file is running but the default printer isn't being set.  Again, when I run the .bat locally it works fine.  I also tested just running the command directly from the Ghost Console instead of executing a .bat and I had the same result.

    Message Edited by Remmie Boston on 05-02-200702:03 PM



  • 4.  RE: Problems Executing Command from Ghost Console

    Posted May 02, 2007 04:59 PM

    Have you tried making a package to distribute via ghost with the batch file?

     

    Right now all I can think is that the remote execution that ghost is trying is not working because the rundll32 is requiring a shell with desktop interaction even if you suppress prompts etc...



  • 5.  RE: Problems Executing Command from Ghost Console

    Posted May 02, 2007 05:44 PM
    Hi Remmie

    Commands executed by Ghost Console on the client are executed in the user context of 'Local System'. The command you are running is usually executed in a user context. Setting the default printer for the Local System user is probably not what you intend.

    The rundll command line in practice really only does one thing, which is to set data for the following registry key and value:

    Key: HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows
    Value: Device
    Data: [Printer data]

    If you set the default printer manually and then inspect this value, you will have the data you need. You can then execute a batch file from console containing Windows REG LOAD commands to load the registry for each user and REG ADD commands to write that data to the registry for each user.

    Quite coincidently, I'm currently working on a generic script of this kind, which I'll post to the forums when it is complete. This could be a few days or longer, as other work gets prioirity.

    If it is a new machine and your users have not logged in before you can set this value for the Windows .Default user in one step using REG ADD without any need for REG LOAD. New users logging in will have your specified default printer to start with.

    Key: HKUSERS\Software\Microsoft\Windows NT\CurrentVersion\Windows
    Value: Device
    Data: [Printer data]

    Regards
    Xan

    Message Edited by Xan Todd on 05-03-200710:59 AM



  • 6.  RE: Problems Executing Command from Ghost Console

    Posted May 03, 2007 12:11 AM
    Hi Remmie

    This took me less time than expected.

    The script is (very) crude but effective. Ensure all users are logged off when it is executed. The script does not set the default printer for any users who are logged on.

    The script updates the default printer for all existing users on the machine, and updates the default printer for the windows .default user.

    Fill the UserRoot and Data values for your system, and you are ready to go.

    I've tested this with XPSP2 and would expect it to work for 2K as well. I've tested transfer to c: root and execution from there.

    @echo off
    If NOT "%1"=="" Goto Update

    REM ** User Data ***
    Set UserRoot=C:\Documents and Settings
    Set KeyName=Software\Microsoft\Windows NT\CurrentVersion\Windows
    Set Value=Device
    Set ValueType=REG_SZ
    Set Data=[Your printer data]

    REM ** Internal Data***
    REG ADD HKU\.Default\%Keyname% /v "%Value%" /t "%ValueType%" /d "%Data%" /f
    FOR /F %%p IN ('dir /b "%UserRoot%"') DO %0 %%p
    :Update
    Set UserPath=%1
    Set TempKey=HKU\TEMP
    Echo Path = %UserRoot%\%UserPath%\NTUSER.Dat
    REG LOAD "%TempKey%" "%UserRoot%\%UserPath%\NTUSER.Dat"
    REG ADD "%TempKey%\%KeyName%" /v "%Value%" /t "%ValueType%" /d "%Data%" /f
    REG UNLOAD "%TempKey%"

    Message Edited by Xan Todd on 05-03-200705:22 PM



  • 7.  RE: Problems Executing Command from Ghost Console

    Posted May 03, 2007 04:45 PM
    Xan Todd,
     
    This script seems to do the trick.  Thanks!