Announcement

Collapse
No announcement yet.

Help with login script

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Help with login script

    Hi,

    I am getting a Syntax Error on line 89 Char 18, code 800A03EA... I am using cutt and paste from a MS Technet article (with regards to this section)... Can anyone tell what I am doing wrong please?

    Code:
    Const CSIDL_DESKTOP = &H10
    Dim strLNKPath, strLNKname
    Dim strTarget, strArguments
    Dim sDriveLetter, strUNC
    Dim objNetwork: set objNetwork = CreateObject("WScript.Network")
    Dim WshShell: set WshShell = CreateObject("WScript.Shell")
    Dim oShell: Set oShell = CreateObject("Shell.Application")
    Dim oDesktop: Set oDesktopFolder = oShell.Namespace(CSIDL_DESKTOP)
    Dim strDesktopFolder: strDesktopFolder = oDesktopFolder.Self.path
    'duplicate part between ---- sDriveLetter = "Z:"  strUNC = "\\server\sharedfolder"  strLNKname = "Network Share 1"
    '-----------------------------------------------------------------------
    '                          Mapping 1
    '
    '# Map drive:
    sDriveLetter = "Z:"
    strUNC = "\\HAL9000-SERVER\Downloads"
    Call MapDrive(sDriveLetter, strUNC)
    '# Create shortcut:
    strLNKPath = strDesktopFolder
    strLNKname = "Network Share 1"
    strTarget = "explorer.exe"
    strArguments = "/e,/root," & sDriveLetter & "\"
    Call CreateShortcut(strLNKPath, strLNKname, strTarget, strArguments)
    '# Mapping's alias: (optional - remove 'rem' to activate this routine)
    rem Call NameMapping(strLNKname)
    '-----------------------------------------------------------------------
    '-----------------------------------------------------------------------
    '                          Mapping 2
    '
    '# Map drive:
    sDriveLetter = "Y:"
    strUNC = "\\HAL9000-SERVER\Logs"
    Call MapDrive(sDriveLetter, strUNC)
    '# Create shortcut:
    strLNKPath = strDesktopFolder
    strLNKname = "Network Share 2"
    strTarget = "explorer.exe"
    strArguments = "/e,/root," & sDriveLetter & "\"
    Call CreateShortcut(strLNKPath, strLNKname, strTarget, strArguments)
    '# Mapping's alias: (optional - remove 'rem' to activate this routine)
    rem Call NameMapping(strLNKname)
    '-----------------------------------------------------------------------
    ' next mappings and shortcuts....
    wscript.quit
     
    Sub CreateShortcut(sFolder, sName, sTarget, sArgs)
       With WshShell '(has a global scope)
          With .CreateShortcut(sFolder &"\" & sName  &".LNK")
             .TargetPath = sTarget
             .Description = sName
             .Arguments = sArgs
             .IconLocation = "shell32.dll, 9"
             .WindowStyle = 3
             .WorkingDirectory = "."
             .Save
          End With
       End With
    End Sub
    Sub MapDrive(DriveLetter, Share)
       On Error Resume Next
       With objNetwork
          .MapNetworkDrive DriveLetter, Share, False
       End With
    End Sub
    Sub NameMapping(sAlias)
       With oShell
          .NameSpace(sDriveLetter).Self.Name = sAlias
       End With
    '-----------------------------------------------------------------------
    'START OFFICE 2007
    '-----------------------------------------------------------------------
    setlocal
    REM *********************************************************************
    REM Environment customization begins here. Modify variables below.
    REM *********************************************************************
    REM Get ProductName from the Office product's core Setup.xml file.
    set ProductName=Standard
    REM Set DeployServer to a network-accessible location containing the Office source files.
    set DeployServer=\\hal9000-server\distribution$\applications\Office2007
    REM Set ConfigFile to the configuration file to be used for deployment REM (required)
    set ConfigFile=\\hal9000-server\distribution$\application\Office2007\Standard.WW\config.xml
    REM Set LogLocation to a central directory to collect log files.
    set LogLocation=\\hal9000-server\distribution$\application\Office2007\Logs
    REM *********************************************************************
    REM Deployment code begins here. Do not modify anything below this line.
    REM *********************************************************************
    IF NOT "%ProgramFiles(x86)%"=="" SET WOW6432NODE=WOW6432NODE\
    reg query HKEY_LOCAL_MACHINE\SOFTWARE\%WOW6432NODE%Microsoft\Windows\CurrentVersion\Uninstall\%ProductName%
    if %errorlevel%==1 (goto DeployOffice) else (goto End)
    REM If 1 returned, the product was not found. Run setup here.
    :DeployOffice
    start /wait %DeployServer%\setup.exe /config %ConfigFile%
    echo %date% %time% Setup ended with error code %errorlevel%. >> %LogLocation%\%computername%.txt
    REM If 0 or other was returned, the product was found or another error occurred. Do nothing.
    :End
    Endlocal

  • #2
    Re: Help with login script

    You are mixing Batch and VBScript. Unless there is a copy-paste error, the sub that begins on row 65 never ends properly. The code abruptly changes into batch language. On which Technet page you are referring to?

    Code:
    65: Sub NameMapping(sAlias)
    66:   With oShell
    67:      .NameSpace(sDriveLetter).Self.Name = sAlias
    68:   End With
    ...
    87: IF NOT "%ProgramFiles(x86)%"=="" SET WOW6432NODE=WOW6432NODE\
    88: reg query HKEY_LOCAL_MACHINE\SOFTWARE\%WOW6432NODE%Microsoft
    \Windows\CurrentVersion\Uninstall\%ProductName%
    89: if %errorlevel%==1 (goto DeployOffice) else (goto End)
    -vP

    Comment


    • #3
      Re: Help with login script

      http://technet.microsoft.com/en-us/l.../cc179134.aspx

      This one...


      So should I do a seperate login script as a .bat file (in addition to the .vbs one?) or is there a vbs one to do this?

      I am not able to buy the console manager which makes this a bit easier I think.

      Any help would be appreciated.

      Comment


      • #4
        Re: Help with login script

        It would be allright if the batch and vbs are executed seperately as startupscripts by the same GPO.
        (For software installation by a startup script you might consider to "Run startup scripts asynchronously".)

        It is also possible to covert the batch script to vbs and add the code to the existing vbs.
        Here are two vbs samples to help you started:
        SWexist = FALSE
        Set colSoftware = List Installed Software
        For Each objSoftware in colSoftware
        If lcase(objSoftware.Name) = lcase("....") Then
        SWexist = TRUE
        exit For
        End If
        Next
        If SWexist = FALSE Then
        - Install Software on the Local Computer
        End If



        \Rems
        Last edited by Rems; 12th May 2009, 19:02.

        This posting is provided "AS IS" with no warranties, and confers no rights.

        __________________

        ** Remember to give credit where credit's due **
        and leave Reputation Points for meaningful posts

        Comment


        • #5
          Re: Help with login script

          Ok, I have them seperated and they are running fine...I just had the bat file run the vbs. The only issue is that it runs the bat file twice...

          I have searched and it looks like this is because I am using loopback processing mode (have this turned on because I am using GP to block internet access using a fake proxy on some computers)

          I am applying the gp to install software to the domain, so maybe this is the issue? How would I fix this little glitch? It's really not a major issue because it only really causes an error of word saying you can't run two setups (if it doesn't find word), otherwise it is working fine.

          Thanks,
          Allen

          Comment


          • #6
            Re: Help with login script

            Originally posted by chakotay2 View Post
            Ok, I have them seperated and they are running fine...I just had the bat file run the vbs. The only issue is that it runs the bat file twice...

            I have searched and it looks like this is because I am using loopback processing mode (have this turned on because I am using GP to block internet access using a fake proxy on some computers)

            I am applying the gp to install software to the domain, so maybe this is the issue? How would I fix this little glitch? It's really not a major issue because it only really causes an error of word saying you can't run two setups (if it doesn't find word), otherwise it is working fine.

            Thanks,
            Allen
            Let the batch check if Windows Installer is currently running already, and end the batch if it is. By adding this condition to the batch,
            Code:
            @echo off
            tasklist | find /c /i "MSIExec.exe" &&(goto:eof)
            
            rem your code comes here
            Or, for general purpose you could make the script write a flag file. When the batch is running it will check the flag file to determine if it has been executed already that same day.
            Code:
            @echo off 
            
            :: date last run -------------------------------------------------------
            SetLocal & set "flag=setupo2k7"
            
            for /f "tokens=2-4 skip=1 delims=(-./)" %%i in ('echo.^|date') do (
             If exist "%windir%.\temp\%flag%" (
              for /f "tokens=1-4 delims=-./ " %%m in (
               'cmd /c dir /TW "%windir%.\temp\%flag%" /4 ^| find /i "%flag%"'
               ) do (
               Call:dateformat DateLastRun "%%i=%%m" "%%j=%%n" "yy=%%o"
              )
             ) Else (Set DateLastRun=00000000)
             for /f "tokens=1-4 delims=-./ " %%q in ('date /t') do (
              Call:dateformat DateToday "%%i=%%r" "%%j=%%s" "yy=%%t"
             )
            ) & > "%windir%.\temp\%flag%" echo\
            
            If %DateToday% EQU %DateLastRun% (
               echo already executed today
               goto:eof ENDING THE BATCH
            ) Else (EndLocal & goto:main script)
            
            :dateformat routine
            set "yy=" & set "mm=" & set "dd="
            Set %2
            Set %3
            Set %4
            Set %1=%yy%%mm%%dd%
            
            goto:eof
            :main script -----------------------------------------------------------
            
            rem your batch comes here
            General purpose: In addition, to make the flag file depend on the current user, replace all instances of:
            "%windir%.\temp\%flag%" with: "%temp%.\%flag%"


            \Rems
            Last edited by Rems; 13th May 2009, 09:42.

            This posting is provided "AS IS" with no warranties, and confers no rights.

            __________________

            ** Remember to give credit where credit's due **
            and leave Reputation Points for meaningful posts

            Comment


            • #7
              Re: Help with login script

              It's still running twice.... here is what I currently have:

              Code:
              REM (taking this script out of the picture for simplicity) -- \\ccwtech.com\SYSVOL\ccwtech.com\Policies\{2D1D1D11-BDBC-4051-ABAA-888AD8419E7D}\User\Scripts\Logon\map.vbs
              @echo off
              tasklist | find /i "MSIExec.exe" &&(goto:eof)
              REM-----------------------------------------------------------------------
              REM START OFFICE 2007
              REM-----------------------------------------------------------------------
              setlocal
              REM *********************************************************************
              REM Environment customization begins here. Modify variables below.
              REM *********************************************************************
              REM Get ProductName from the Office product's core Setup.xml file.
              set ProductName=Standard
              REM Set DeployServer to a network-accessible location containing the Office source files.
              set DeployServer=\\hal9000-server\distribution$\applications\Office2007
              REM Set ConfigFile to the configuration file to be used for deployment REM (required)
              set ConfigFile=\\hal9000-server\distribution$\applications\Office2007\Standard.WW\config.xml
              REM Set LogLocation to a central directory to collect log files.
              set LogLocation=\\hal9000-server\distribution$\applications\Office2007\Logs
              REM *********************************************************************
              REM Deployment code begins here. Do not modify anything below this line.
              REM *********************************************************************
              IF NOT "%ProgramFiles(x86)%"=="" SET WOW6432NODE=WOW6432NODE\
              reg query HKEY_LOCAL_MACHINE\SOFTWARE\%WOW6432NODE%Microsoft\Windows\CurrentVersion\Uninstall\%ProductName%
              if %errorlevel%==1 (goto DeployOffice) else (goto End)
              REM If 1 returned, the product was not found. Run setup here.
              :DeployOffice
              start /wait %DeployServer%\setup.exe /config %ConfigFile%
              echo %date% %time% Setup ended with error code %errorlevel%. >> %LogLocation%\%computername%.txt
              REM If 0 or other was returned, the product was found or another error occurred. Do nothing.
              :End
              Endlocal
              Last edited by chakotay2; 13th May 2009, 00:33.

              Comment


              • #8
                Re: Help with login script

                As the Office setup is started via setup.exe, shouldn't one be checking if setup.exe is running instead of Msiexec.exe? If Office setup uses Msiexec (it's likely), you could either go with the flag file way, or look for both setup and msiexec processes. Maybe something like this:

                Code:
                tasklist | find /i "Setup.exe" &&(goto:eof)
                tasklist | find /i "MSIExec.exe" &&(goto:eof)
                One caveat would be that running tasklist will sometimes take a few seconds, so look first for the front-end setup.exe and then for the Msi installer binary. The flag file approach avoids this issue and I would prefer it as more reliable a way.

                -vP

                Comment


                • #9
                  Re: Help with login script

                  That didn't work so I switched to the 'date last run script' - looks like it is working beautfifully!

                  Rems & vonPryz - Thanks for all your help... I love this forum!

                  Comment


                  • #10
                    Re: Help with login script

                    Originally posted by vonPryz View Post
                    As the Office setup is started via setup.exe, shouldn't one be checking if setup.exe is running instead of Msiexec.exe?
                    Yes, you have to find out what typical task(s) is/are running during the office installation.
                    Then add them to the findstring:
                    Code:
                    tasklist | findstr /ic:"setup.exe" /ic:"msiexec.exe" &&(goto:eof)
                    Assuming that there is only one startup batch and no logon batches and apparently the startup script is configured to run asynchronously in your environment? Then the batch could run a check first if there currently are more than one instance of CMD.exe running (bit tricky!):
                    Code:
                    for /f %%* in ('tasklist ^| find /c /i "cmd.exe"') Do (
                       If %%* GTR 1 (goto:eof)
                    )
                    Other options you could try are
                    1. experiment with added delays to the batch (although, I am not sure this will really help when startup- and logonscripts are set to run asynchronously).
                    I.e. add a short delay (5 sec) before running the 'tasklist' statement like
                    >nul ping 0.0.0.1 -n 1 -w 5000

                    2. Run the startupscripts and logonscripts both SYNChronously (user will be forced to wait during the installation).

                    3. Use the flag file option

                    4. Simple solution: Try to hide error messages from appearing in the dos box (by redirecting Windows Installer errors to device nul) 2>nul. Or configure to run startupscripts silently (hidden).


                    \Rems


                    EDIT
                    Originally posted by chakotay2 View Post
                    That didn't work so I switched to the 'date last run script' - looks like it is working beautfifully!

                    Rems & vonPryz - Thanks for all your help... I love this forum!
                    I had missed your previous reply.
                    , thanks.
                    Last edited by Rems; 13th May 2009, 10:49.

                    This posting is provided "AS IS" with no warranties, and confers no rights.

                    __________________

                    ** Remember to give credit where credit's due **
                    and leave Reputation Points for meaningful posts

                    Comment

                    Working...
                    X