Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Windows Server Login Script

Posted on 2011-10-26
5
Medium Priority
?
648 Views
Last Modified: 2012-05-12
Hi,

I'm writing a simple login script. all it does is map some drives and create some shortcuts.

I have a little glitch in the code hoping someone could look at it.

here is the code. I think the glitch is somewheres in


-----------------------------------------------------------
 Dim WshShell
 set WshShell = WScript.CreateObject("WScript.Shell")

strWorkDir = WshShell.SpecialFolders("Desktop")
strAppPath = "\\Pervasive\calmed$\maincds.exe"
strIconOpts = "localhost,golden"
strIconPath = "\\Pervasive\calmed$\maincds.exe,5"
strDescription = "Calmed - Golden"

Set objShell = CreateObject("WScript.Shell")
objDesktop = objShell.SpecialFolders("Desktop")
Set objLink = objShell.CreateShortcut(objDesktop & "\Calmed - Golden.lnk")


-----------------------------------------------------------------------------------------





help is appreciated


 
Option Explicit

Dim objNetwork, objShell, objFileSystem
Dim bForce, bUpdateProfile

err.number = vbempty

bForce = "True"
bUpdateProfile = "True"

'Dim DRive Paths

Dim strRemotePath1
Dim strRemotePath2
Dim strRemotePath3

'Dim Drive Letter Var

Dim strDriveLetter1
Dim strDriveLetter2
Dim strDriveLetter3
Dim strDriveLetter4 

err.number = vbempty

Set objNetwork = CreateObject("WScript.Network")
Set objFileSystem = CreateObject("Scripting.FileSystemObject") 
'On Error Resume Next

'objNetwork.RemoveNetworkDrive strDriveLetter, bforce, bUpdateProfile

strDriveLetter1 = "H:"
strDriveLetter2 = "W:"
strDriveLetter3 = "S:"
strDriveLetter4 = "X:"

strRemotePath1 = "\\nas1\wpdocs"
strRemotePath2 = "\\nas1\documents"
strRemotePath3 = "\\nas1\scans"


'Remmoves old map paths
If objFileSystem.DriveExists(strDriveLetter1) Then
    objNetwork.RemoveNetworkDrive strDriveLetter1, True, True 
end if
If objFileSystem.DriveExists(strDriveLetter2) Then
    objNetwork.RemoveNetworkDrive strDriveLetter2, True, True
end if
If objFileSystem.DriveExists(strDriveLetter3) Then
    objNetwork.RemoveNetworkDrive strDriveLetter3, True, True 
end if
If objFileSystem.DriveExists(strDriveLetter4) Then
    objNetwork.RemoveNetworkDrive strDriveLetter4, True, True
End if

'Section which maps drives, H and W: and S:
If Not objFileSystem.DriveExists(strDriveLetter1) Then
    objNetwork.MapNetworkDrive strDriveLetter1, strRemotePath1
End if
If Not objFileSystem.DriveExists(strDriveLetter2) Then
    objNetwork.MapNetworkDrive strDriveLetter2, strRemotePath2
End if
If Not objFileSystem.DriveExists(strDriveLetter3) Then
    objNetwork.MapNetworkDrive strDriveLetter3, strRemotePath3
End if



'Create Shortcut
' ----------------------------------------------------------'


Dim objDesktop, objLink
Dim strAppPath, strWorkDir, strIconPath, strDescription

' --------------------------------------------------
' Here are the variables that to change if you are making a 'real' script

 Dim WshShell
 set WshShell = WScript.CreateObject("WScript.Shell")

strWorkDir = WshShell.SpecialFolders("Desktop")
strAppPath = "\\Pervasive\calmed$\maincds.exe"
strIconOpts = "localhost,golden"
strIconPath = "\\Pervasive\calmed$\maincds.exe,5"
strDescription = "Calmed - Golden"

Set objShell = CreateObject("WScript.Shell")
objDesktop = objShell.SpecialFolders("Desktop")
Set objLink = objShell.CreateShortcut(objDesktop & "\Calmed - Golden.lnk")

' ---------------------------------------------------
' Section which adds the shortcut's key properties

objLink.Description = strDescription
objLink.HotKey = "CTRL+SHIFT+C"
objLink.IconLocation = strIconPath
objLink.Arguments = strIconOpts
objLink.TargetPath = strAppPath
objLink.WindowStyle = 3
objLink.WorkingDirectory = strWorkDir
objLink.Save





strWorkDir = WshShell.SpecialFolders("Desktop")
strAppPath = "http://mail.gssmedical.com:8080"
strIconPath = "C:\WINDOWS\system32\url.dll,5"
strDescription = "GssMedical - Messaging"

Set objShell = CreateObject("WScript.Shell")
objDesktop = objShell.SpecialFolders("Desktop")
Set objLink = objShell.CreateShortcut(objDesktop & "\GssMedical - Messaging.lnk")

' ---------------------------------------------------
' Section which adds the shortcut's key properties

objLink.Description = strDescription
objLink.HotKey = "CTRL+SHIFT+E"
objLink.IconLocation = strIconPath
objLink.Arguments = strIconOpts
objLink.TargetPath = strAppPath
objLink.WindowStyle = 3
objLink.WorkingDirectory = strWorkDir
objLink.Save











'Extra code just to add a message box

'WScript.Echo "Map drives " & strDriveLetter1 & " & " & strDriveLetter2 & " & " & strDriveLetter3

' Error correcting code
'If err.number = vbEmpty then
'Set objShell = CreateObject("WScript.Shell")
'objShell.run ("Explorer")
'ElseIf err.number = -2147022646 then
'Wscript.Echo "You must create " & strDriveLetter
'Else Wscript.echo "Unknown Problem with Login Script" & err.number
'End If

Wscript.Quit

Open in new window

0
Comment
Question by:TheWebGuy38
  • 2
4 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 37034195
>I have a little glitch in the code hoping someone could look at it.

And the glitch is ...
0
 

Author Comment

by:TheWebGuy38
ID: 37034373
heres the error.

something with

 Dim WshShell
 set WshShell = WScript.CreateObject("WScript.Shell")

strWorkDir = WshShell.SpecialFolders("Desktop")
strAppPath = "\\Pervasive\calmed$\maincds.exe"
strIconOpts = "localhost,golden"
strIconPath = "\\Pervasive\calmed$\maincds.exe,5"
strDescription = "Calmed - Golden"

Set objShell = CreateObject("WScript.Shell")
objDesktop = objShell.SpecialFolders("Desktop")
Set objLink = objShell.CreateShortcut(objDesktop & "\Calmed - Golden.lnk")


error
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 2000 total points
ID: 37036122
Try doing a Dim on the strIconOpts.
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 37242275
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

Question has a verified solution.

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

New Windows 7 Installations take days for Windows-Updates to show up and install. This can easily be fixed. I have finally decided to write an article because this seems to get asked several times a day lately. This Article and the Links apply to…
This article provides a convenient collection of links to Microsoft provided Security Patches for operating systems that have reached their End of Life support cycle. Included operating systems covered by this article are Windows XP,  Windows Server…
This tutorial will give a an overview on how to deploy remote agents in Backup Exec 2012 to new servers. Click on the Backup Exec button in the upper left corner. From here, are global settings for the application such as connecting to a remote Back…
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 to another domain controller. Log onto the new domain controller with a user account t…
Suggested Courses

864 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