Windows Vista Tips

Windows Vista Tips > Newsgroups > Windows Server > Scripting > SBS 2003 VB Scripting - Help Needed!

Reply
Thread Tools Display Modes

SBS 2003 VB Scripting - Help Needed!

 
 
un1c0rn
Guest
Posts: n/a

 
      03-10-2009
Hello Gurus,

I am currently working on a login script for a Small Business Server 2003
which maps drives and creates different default printers depending on which
security group the users are in. The drive mapping works ok but the default
printing assignment has errors when running the vb script. I am sure it is
something simple that I am missing here but I can't seem to get my head
around it. Any help would be muchly appreciated.

Thankyou in Advance.

My scripting is below:

Option Explicit



' Common Commands - For All Users.

Dim wshell

Set wshell = CreateObject("WScript.Shell")

wshell.Run "%COMSPEC% /c net time \\SBSERVER /set /y",0,TRUE

wshell.Run "%COMSPEC% /c net use /delete /y *",0,TRUE

' wshell.Run "%COMSPEC% \\SBSERVER\Clients\Setup\setup.exe /s SBSERVER

set wshell = Nothing



' Assign Drive Mappings.

Dim objNetwork, strRemotePath1, strRemotePath2, strRemotePath3

Dim strDriveLetter1, strDriveLetter2, strDriveLetter3

strDriveLetter1 = "K:"

strDriveLetter2 = "L:"

strDriveLetter3 = "M:"

strRemotePath1 = "\\SQLSVR\APPS"

strRemotePath2 = "\\SQLSVR\DATA"

strRemotePath3 = "\\SQLSVR\MYOBAE"

Set objNetwork = WScript.CreateObject("WScript.Network")

objNetwork.MapNetworkDrive strDriveLetter1, strRemotePath1

objNetwork.MapNetworkDrive strDriveLetter2, strRemotePath2

objNetwork.MapNetworkDrive strDriveLetter3, strRemotePath3



' Assign Default Printer - according to security group membership.

dim objGroup1, objGroup2, objGroup3, strUserDN, objSysInfo

Set objGroup1 = GetObject("LDAP://cn=BACK OFFICE TOSHIBA,ou=Security
Groups,ou=MyBusiness,dc=Domain,dc=local")

Set objSysInfo = CreateObject("ADSystemInfo")

strUserDN = objSysInfo.userName

If (objGroup1.IsMember("LDAP://" & strUserDN) = True) Then

objNetwork.AddWindowsPrinterConnection "\\sbserver\BACKOFFICE PRINTER"

objNetwork.SetDefaultPrinter "\\sbserver\BACKOFFICE PRINTER"

Else

Set objGroup2 = GetObject("LDAP://cn=FRONT OFFICE TOSHIBA,ou=Security
Groups,ou=MyBusiness,dc=Domain,dc=local")

If (objGroup2.IsMember("LDAP://" & strUserDN) = True) Then

objNetwork.AddWindowsPrinterConnection "\\sbserver\FRONT OFFICE TOSHIBA"

objNetwork.SetDefaultPrinter "\\sbserver\FRONT OFFICE TOSHIBA"

Else

Set objGroup3 = GetObject("LDAP://cn=COLOUR PRINTER,ou=Security
Groups,ou=MyBusiness,dc=Domain,dc=local")

If (objGroup3.IsMember("LDAP://" & strUserDN) = True) Then

objNetwork.AddWindowsPrinterConnection "\\sbserver\COLOUR PRINTER"

objNetwork.SetDefaultPrinter "\\sbserver\COLOUR PRINTER"

End If

End If

End If

WScript.Quit

' End of VBScript.


 
Reply With Quote
 
 
 
 
Richard Mueller [MVP]
Guest
Posts: n/a

 
      03-10-2009

"T Lavedas" <> wrote in message
news:11817978-171b-4c3c-9198-...
On Mar 10, 7:23 am, "un1c0rn" <un1c...@yahoo.com> wrote:
> Hello Gurus,
>
> I am currently working on a login script for a Small Business Server 2003
> which maps drives and creates different default printers depending on
> which
> security group the users are in. The drive mapping works ok but the
> default
> printing assignment has errors when running the vb script. I am sure it is
> something simple that I am missing here but I can't seem to get my head
> around it. Any help would be muchly appreciated.
>
> Thankyou in Advance.
>
> My scripting is below:
>

{code snipped}

What error? What line? Trying to find unnamed errors is like trying
to collect smoke in a bottle.

Tom Lavedas
***********
http://there.is.no.more/tglbatch/
------------------

The code looks fine to me also, unless one of the DN's is invalid in your
AD. I would suggest running the script after logon to troubleshoot.

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--


 
Reply With Quote
 
Al Dunbar
Guest
Posts: n/a

 
      03-10-2009

"T Lavedas" <> wrote in message
news:11817978-171b-4c3c-9198-...
On Mar 10, 7:23 am, "un1c0rn" <un1c...@yahoo.com> wrote:
> Hello Gurus,
>
> I am currently working on a login script for a Small Business Server 2003
> which maps drives and creates different default printers depending on
> which
> security group the users are in. The drive mapping works ok but the
> default
> printing assignment has errors when running the vb script. I am sure it is
> something simple that I am missing here but I can't seem to get my head
> around it. Any help would be muchly appreciated.
>
> Thankyou in Advance.
>
> My scripting is below:
>

{code snipped}

What error? What line? Trying to find unnamed errors is like trying
to collect smoke in a bottle.

============
But that can be done. I'd say it is more like trying to collect smoke in a
cloth bag. ;-)

/Al


 
Reply With Quote
 
un1c0rn
Guest
Posts: n/a

 
      03-10-2009
Ok I have the error message that occurs when I run the vbs script.

Error Message:
Line: 52
Char: 1
Error: The filename, directory name, or volume label syntax is incorrect.
Code: 8007007B
Source: (null)
 
Reply With Quote
 
un1c0rn
Guest
Posts: n/a

 
      03-10-2009
Line: 52
Char: 1
Error: The filename, directory name, or volume label syntax is incorrect.
Code: 8007007B
Source: (null)

"T Lavedas" <> wrote in message
news:11817978-171b-4c3c-9198-...
On Mar 10, 7:23 am, "un1c0rn" <un1c...@yahoo.com> wrote:
> Hello Gurus,
>
> I am currently working on a login script for a Small Business Server 2003
> which maps drives and creates different default printers depending on
> which
> security group the users are in. The drive mapping works ok but the
> default
> printing assignment has errors when running the vb script. I am sure it is
> something simple that I am missing here but I can't seem to get my head
> around it. Any help would be muchly appreciated.
>
> Thankyou in Advance.
>
> My scripting is below:
>

{code snipped}

What error? What line? Trying to find unnamed errors is like trying
to collect smoke in a bottle.

Tom Lavedas
***********
http://there.is.no.more/tglbatch/

 
Reply With Quote
 
Pegasus
Guest
Posts: n/a

 
      03-10-2009

"un1c0rn" <> wrote in message
news:5F242748-F19D-4162-A05A-...
> Ok I have the error message that occurs when I run the vbs script.
>
> Error Message:
> Line: 52
> Char: 1
> Error: The filename, directory name, or volume label syntax is incorrect.
> Code: 8007007B
> Source: (null)


You're still leaving it to respondents to count lines. How about giving us
the actual line that generates the error?


 
Reply With Quote
 
un1c0rn
Guest
Posts: n/a

 
      03-10-2009
Windows Script Host
Script: c:\documents and settings\sysop\desktop\test.vbs
line: 52
Char: 1
Error: The filename, directory name, or volume label syntax is incorrect.
Code: 8007007b
Source: (null)
"un1c0rn" <> wrote in message
news:...
> Hello Gurus,
>
> I am currently working on a login script for a Small Business Server 2003
> which maps drives and creates different default printers depending on
> which security group the users are in. The drive mapping works ok but the
> default printing assignment has errors when running the vb script. I am
> sure it is something simple that I am missing here but I can't seem to get
> my head around it. Any help would be muchly appreciated.
>
> Thankyou in Advance.
>
> My scripting is below:
>
> Option Explicit
>
>
>
> ' Common Commands - For All Users.
>
> Dim wshell
>
> Set wshell = CreateObject("WScript.Shell")
>
> wshell.Run "%COMSPEC% /c net time \\SBSERVER /set /y",0,TRUE
>
> wshell.Run "%COMSPEC% /c net use /delete /y *",0,TRUE
>
> ' wshell.Run "%COMSPEC% \\SBSERVER\Clients\Setup\setup.exe /s SBSERVER
>
> set wshell = Nothing
>
>
>
> ' Assign Drive Mappings.
>
> Dim objNetwork, strRemotePath1, strRemotePath2, strRemotePath3
>
> Dim strDriveLetter1, strDriveLetter2, strDriveLetter3
>
> strDriveLetter1 = "K:"
>
> strDriveLetter2 = "L:"
>
> strDriveLetter3 = "M:"
>
> strRemotePath1 = "\\SQLSVR\APPS"
>
> strRemotePath2 = "\\SQLSVR\DATA"
>
> strRemotePath3 = "\\SQLSVR\MYOBAE"
>
> Set objNetwork = WScript.CreateObject("WScript.Network")
>
> objNetwork.MapNetworkDrive strDriveLetter1, strRemotePath1
>
> objNetwork.MapNetworkDrive strDriveLetter2, strRemotePath2
>
> objNetwork.MapNetworkDrive strDriveLetter3, strRemotePath3
>
>
>
> ' Assign Default Printer - according to security group membership.
>
> dim objGroup1, objGroup2, objGroup3, strUserDN, objSysInfo
>
> Set objGroup1 = GetObject("LDAP://cn=BACK OFFICE TOSHIBA,ou=Security
> Groups,ou=MyBusiness,dc=Domain,dc=local")
>
> Set objSysInfo = CreateObject("ADSystemInfo")
>
> strUserDN = objSysInfo.userName
>
> If (objGroup1.IsMember("LDAP://" & strUserDN) = True) Then
>
> objNetwork.AddWindowsPrinterConnection "\\sbserver\BACKOFFICE PRINTER"
>
> objNetwork.SetDefaultPrinter "\\sbserver\BACKOFFICE PRINTER"
>
> Else
>
> Set objGroup2 = GetObject("LDAP://cn=FRONT OFFICE TOSHIBA,ou=Security
> Groups,ou=MyBusiness,dc=Domain,dc=local")
>
> If (objGroup2.IsMember("LDAP://" & strUserDN) = True) Then
>
> objNetwork.AddWindowsPrinterConnection "\\sbserver\FRONT OFFICE TOSHIBA"
>
> objNetwork.SetDefaultPrinter "\\sbserver\FRONT OFFICE TOSHIBA"
>
> Else
>
> Set objGroup3 = GetObject("LDAP://cn=COLOUR PRINTER,ou=Security
> Groups,ou=MyBusiness,dc=Domain,dc=local")
>
> If (objGroup3.IsMember("LDAP://" & strUserDN) = True) Then
>
> objNetwork.AddWindowsPrinterConnection "\\sbserver\COLOUR PRINTER"
>
> objNetwork.SetDefaultPrinter "\\sbserver\COLOUR PRINTER"
>
> End If
>
> End If
>
> End If
>
> WScript.Quit
>
> ' End of VBScript.
>
>


 
Reply With Quote
 
un1c0rn
Guest
Posts: n/a

 
      03-10-2009
Windows Script Host
Script: c:\documents and settings\sysop\desktop\test.vbs
line: 52
Char: 1
Error: The filename, directory name, or volume label syntax is incorrect.
Code: 8007007b
Source: (null)

"un1c0rn" <> wrote in message
news:...
> Hello Gurus,
>
> I am currently working on a login script for a Small Business Server 2003
> which maps drives and creates different default printers depending on
> which security group the users are in. The drive mapping works ok but the
> default printing assignment has errors when running the vb script. I am
> sure it is something simple that I am missing here but I can't seem to get
> my head around it. Any help would be muchly appreciated.
>
> Thankyou in Advance.
>
> My scripting is below:
>
> Option Explicit
>
>
>
> ' Common Commands - For All Users.
>
> Dim wshell
>
> Set wshell = CreateObject("WScript.Shell")
>
> wshell.Run "%COMSPEC% /c net time \\SBSERVER /set /y",0,TRUE
>
> wshell.Run "%COMSPEC% /c net use /delete /y *",0,TRUE
>
> ' wshell.Run "%COMSPEC% \\SBSERVER\Clients\Setup\setup.exe /s SBSERVER
>
> set wshell = Nothing
>
>
>
> ' Assign Drive Mappings.
>
> Dim objNetwork, strRemotePath1, strRemotePath2, strRemotePath3
>
> Dim strDriveLetter1, strDriveLetter2, strDriveLetter3
>
> strDriveLetter1 = "K:"
>
> strDriveLetter2 = "L:"
>
> strDriveLetter3 = "M:"
>
> strRemotePath1 = "\\SQLSVR\APPS"
>
> strRemotePath2 = "\\SQLSVR\DATA"
>
> strRemotePath3 = "\\SQLSVR\MYOBAE"
>
> Set objNetwork = WScript.CreateObject("WScript.Network")
>
> objNetwork.MapNetworkDrive strDriveLetter1, strRemotePath1
>
> objNetwork.MapNetworkDrive strDriveLetter2, strRemotePath2
>
> objNetwork.MapNetworkDrive strDriveLetter3, strRemotePath3
>
>
>
> ' Assign Default Printer - according to security group membership.
>
> dim objGroup1, objGroup2, objGroup3, strUserDN, objSysInfo
>
> Set objGroup1 = GetObject("LDAP://cn=BACK OFFICE TOSHIBA,ou=Security
> Groups,ou=MyBusiness,dc=Domain,dc=local")
>
> Set objSysInfo = CreateObject("ADSystemInfo")
>
> strUserDN = objSysInfo.userName
>
> If (objGroup1.IsMember("LDAP://" & strUserDN) = True) Then
>
> objNetwork.AddWindowsPrinterConnection "\\sbserver\BACKOFFICE PRINTER"
>
> objNetwork.SetDefaultPrinter "\\sbserver\BACKOFFICE PRINTER"
>
> Else
>
> Set objGroup2 = GetObject("LDAP://cn=FRONT OFFICE TOSHIBA,ou=Security
> Groups,ou=MyBusiness,dc=Domain,dc=local")
>
> If (objGroup2.IsMember("LDAP://" & strUserDN) = True) Then
>
> objNetwork.AddWindowsPrinterConnection "\\sbserver\FRONT OFFICE TOSHIBA"
>
> objNetwork.SetDefaultPrinter "\\sbserver\FRONT OFFICE TOSHIBA"
>
> Else
>
> Set objGroup3 = GetObject("LDAP://cn=COLOUR PRINTER,ou=Security
> Groups,ou=MyBusiness,dc=Domain,dc=local")
>
> If (objGroup3.IsMember("LDAP://" & strUserDN) = True) Then
>
> objNetwork.AddWindowsPrinterConnection "\\sbserver\COLOUR PRINTER"
>
> objNetwork.SetDefaultPrinter "\\sbserver\COLOUR PRINTER"
>
> End If
>
> End If
>
> End If
>
> WScript.Quit
>
> ' End of VBScript.
>
>


 
Reply With Quote
 
Al Dunbar
Guest
Posts: n/a

 
      03-15-2009

"un1c0rn" <> wrote in message
news:8B107A64-94A6-452E-BB67-...
> Windows Script Host
> Script: c:\documents and settings\sysop\desktop\test.vbs
> line: 52
> Char: 1
> Error: The filename, directory name, or volume label syntax is incorrect.
> Code: 8007007b
> Source: (null)


Sorry, but we are NOT going to count the lines to figure out which one is
number 52. Use your text editor to find line 52 in the file you ran when
you got this error, and cut-and-paste that line into a reply here.

/Al

> "un1c0rn" <> wrote in message
> news:...
>> Hello Gurus,
>>
>> I am currently working on a login script for a Small Business Server 2003
>> which maps drives and creates different default printers depending on
>> which security group the users are in. The drive mapping works ok but
>> the default printing assignment has errors when running the vb script. I
>> am sure it is something simple that I am missing here but I can't seem to
>> get my head around it. Any help would be muchly appreciated.
>>
>> Thankyou in Advance.
>>
>> My scripting is below:
>>
>> Option Explicit
>>
>>
>>
>> ' Common Commands - For All Users.
>>
>> Dim wshell
>>
>> Set wshell = CreateObject("WScript.Shell")
>>
>> wshell.Run "%COMSPEC% /c net time \\SBSERVER /set /y",0,TRUE
>>
>> wshell.Run "%COMSPEC% /c net use /delete /y *",0,TRUE
>>
>> ' wshell.Run "%COMSPEC% \\SBSERVER\Clients\Setup\setup.exe /s SBSERVER
>>
>> set wshell = Nothing
>>
>>
>>
>> ' Assign Drive Mappings.
>>
>> Dim objNetwork, strRemotePath1, strRemotePath2, strRemotePath3
>>
>> Dim strDriveLetter1, strDriveLetter2, strDriveLetter3
>>
>> strDriveLetter1 = "K:"
>>
>> strDriveLetter2 = "L:"
>>
>> strDriveLetter3 = "M:"
>>
>> strRemotePath1 = "\\SQLSVR\APPS"
>>
>> strRemotePath2 = "\\SQLSVR\DATA"
>>
>> strRemotePath3 = "\\SQLSVR\MYOBAE"
>>
>> Set objNetwork = WScript.CreateObject("WScript.Network")
>>
>> objNetwork.MapNetworkDrive strDriveLetter1, strRemotePath1
>>
>> objNetwork.MapNetworkDrive strDriveLetter2, strRemotePath2
>>
>> objNetwork.MapNetworkDrive strDriveLetter3, strRemotePath3
>>
>>
>>
>> ' Assign Default Printer - according to security group membership.
>>
>> dim objGroup1, objGroup2, objGroup3, strUserDN, objSysInfo
>>
>> Set objGroup1 = GetObject("LDAP://cn=BACK OFFICE TOSHIBA,ou=Security
>> Groups,ou=MyBusiness,dc=Domain,dc=local")
>>
>> Set objSysInfo = CreateObject("ADSystemInfo")
>>
>> strUserDN = objSysInfo.userName
>>
>> If (objGroup1.IsMember("LDAP://" & strUserDN) = True) Then
>>
>> objNetwork.AddWindowsPrinterConnection "\\sbserver\BACKOFFICE PRINTER"
>>
>> objNetwork.SetDefaultPrinter "\\sbserver\BACKOFFICE PRINTER"
>>
>> Else
>>
>> Set objGroup2 = GetObject("LDAP://cn=FRONT OFFICE TOSHIBA,ou=Security
>> Groups,ou=MyBusiness,dc=Domain,dc=local")
>>
>> If (objGroup2.IsMember("LDAP://" & strUserDN) = True) Then
>>
>> objNetwork.AddWindowsPrinterConnection "\\sbserver\FRONT OFFICE TOSHIBA"
>>
>> objNetwork.SetDefaultPrinter "\\sbserver\FRONT OFFICE TOSHIBA"
>>
>> Else
>>
>> Set objGroup3 = GetObject("LDAP://cn=COLOUR PRINTER,ou=Security
>> Groups,ou=MyBusiness,dc=Domain,dc=local")
>>
>> If (objGroup3.IsMember("LDAP://" & strUserDN) = True) Then
>>
>> objNetwork.AddWindowsPrinterConnection "\\sbserver\COLOUR PRINTER"
>>
>> objNetwork.SetDefaultPrinter "\\sbserver\COLOUR PRINTER"
>>
>> End If
>>
>> End If
>>
>> End If
>>
>> WScript.Quit
>>
>> ' End of VBScript.
>>
>>

>




 
Reply With Quote
 
un1c0rn
Guest
Posts: n/a

 
      03-17-2009
Thanks for your help/interest but I have worked it out. The following is
the script I ended up with and works perfectly.

' -----------------------------------------------------------------'
' Company Login Script
' Version 1.0 - 12/03/2009
' -----------------------------------------------------------------'


' -----------------------------------------------------------------'
' Common Commands - For All Users.
' -----------------------------------------------------------------'

ON ERROR RESUME NEXT

Dim WSHShell, WSHNetwork, objDomain, DomainString, UserString, UserObj,
Path, wshell


Set WSHShell = CreateObject("WScript.Shell")
Set WSHNetwork = CreateObject("WScript.Network")
'Automatically grab the user's domain name
DomainString = Wshnetwork.UserDomain
'Find the Windows Directory
WinDir = WshShell.ExpandEnvironmentStrings("%WinDir%")

UserString = WSHNetwork.UserName
Set UserObj = GetObject("WinNT://" & DomainString & "/" & UserString)

strComputer = WSHNetwork.ComputerName


' -----------------------------------------------------------------'
' Syncronise Time
' -----------------------------------------------------------------'
wshshell.Run "%COMSPEC% /c net time \\SBSERVER /set /y",0,TRUE


' -----------------------------------------------------------------'
' Trend Client Install (If not present)
' -----------------------------------------------------------------'
wshshell.Exec "%COMSPEC% \\SBSERVER\Clients\Setup\setup.exe /s SBSERVER"


' -----------------------------------------------------------------'
' Remove Any Existing Mapped Drives and Printers
' -----------------------------------------------------------------'
wshshell.Run "%COMSPEC% /c net use /delete /y *",0,TRUE

Set clDrives = WshNetwork.EnumNetworkDrives
For i = 0 to clDrives.Count -1 Step 2
WSHNetwork.RemoveNetworkDrive clDrives.Item(i), True, True
Next

wscript.sleep 300

Set WSHPrinters = WSHNetwork.EnumPrinterConnections
For LOOP_COUNTER = 0 To WSHPrinters.Count - 1 Step 2
If Left(WSHPrinters.Item(LOOP_COUNTER +1),2) = "\\" Then
WSHNetwork.RemovePrinterConnection WSHPrinters.Item(LOOP_COUNTER
+1),True,True
End If
Next

wscript.sleep 300


' -----------------------------------------------------------------'
' Assign Mapped Drives
' -----------------------------------------------------------------'

WSHNetwork.MapNetworkDrive "H:", "\\sbserver\users\" & UserString,True
WSHNetwork.MapNetworkDrive "K:", "\\SQLSVR\APPS",True
WSHNetwork.MapNetworkDrive "L:", "\\SQLSVR\DATA",True
WSHNetwork.MapNetworkDrive "M:", "\\SQLSVR\MYOBAE",True


' -----------------------------------------------------------------'
' Assign Default Printer - according to group membership.
' -----------------------------------------------------------------'

For Each GroupObj In UserObj.Groups
Select Case UCase(GroupObj.Name)
Case "CTPRINT1"
WSHNetwork.AddWindowsPrinterConnection "\\sbserver\BACK OFFICE"
WSHNetwork.SetDefaultPrinter "\\sbserver\BACK OFFICE PRINTER"
Case "CTPRINT2"
WSHNetwork.AddWindowsPrinterConnection "\\sbserver\RECEPTION"
WSHNetwork.SetDefaultPrinter "\\sbserver\RECEPTION"
Case "CTPRINT3"
WSHNetwork.AddWindowsPrinterConnection "\\sbserver\HPLaserJ"
WSHNetwork.SetDefaultPrinter "\\sbserver\HPLaserJ"
End Select
Next

set UserObj = Nothing
set GroupObj = Nothing
set WSHNetwork = Nothing
set DomainString = Nothing
set WSHSHell = Nothing
Set WSHPrinters = Nothing

wscript.quit

 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Scripting help needed! John Scripting 0 03-06-2008 05:04 PM
scripting help needed Darren Scripting 1 01-28-2006 05:11 PM
Re: Newbie help needed with scripting permissions Richard Mueller Scripting 0 01-06-2006 01:59 AM
Scripting solution needed for DHCP and trusted PDC/DHCP servers. Scott Cooper Scripting 2 07-15-2004 11:05 PM
Scripting solution needed for DHCP and trusted PDC/DHCP servers. Scott Cooper Server Networking 2 07-15-2004 11:05 PM



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59