Home All Groups Group Topic Archive Search About

SBS 2003 VB Scripting - Help Needed!

Author
10 Mar 2009 11:23 AM
un1c0rn
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.

Author
10 Mar 2009 12:06 PM
T Lavedas
Show quote Hide quote
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/
Author
10 Mar 2009 4:10 PM
Richard Mueller [MVP]
Show quote Hide quote
"T Lavedas" <tglba***@cox.net> wrote in message
news:11817978-171b-4c3c-9198-541475a10aeb@a39g2000yqc.googlegroups.com...
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
--
Author
10 Mar 2009 10:37 PM
Al Dunbar
Show quote Hide quote
"T Lavedas" <tglba***@cox.net> wrote in message
news:11817978-171b-4c3c-9198-541475a10aeb@a39g2000yqc.googlegroups.com...
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
Author
10 Mar 2009 10:59 PM
un1c0rn
Line: 52
Char: 1
Error: The filename, directory name, or volume label syntax is incorrect.
Code: 8007007B
Source: (null)

Show quoteHide quote
"T Lavedas" <tglba***@cox.net> wrote in message
news:11817978-171b-4c3c-9198-541475a10aeb@a39g2000yqc.googlegroups.com...
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/
Author
10 Mar 2009 10:58 PM
un1c0rn
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)
Author
10 Mar 2009 11:20 PM
Pegasus
"un1c0rn" <un1c***@yahoo.com> wrote in message
news:5F242748-F19D-4162-A05A-8A286EE6D4CF@microsoft.com...
> 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?
Author
11 Mar 2009 12:41 AM
un1c0rn
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)
Show quoteHide quote
"un1c0rn" <un1c***@yahoo.com> wrote in message
news:uDPLbKXoJHA.1172@TK2MSFTNGP04.phx.gbl...
> 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.
>
>
Author
11 Mar 2009 12:42 AM
un1c0rn
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)

Show quoteHide quote
"un1c0rn" <un1c***@yahoo.com> wrote in message
news:uDPLbKXoJHA.1172@TK2MSFTNGP04.phx.gbl...
> 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.
>
>
Author
15 Mar 2009 4:52 AM
Al Dunbar
"un1c0rn" <un1c***@yahoo.com> wrote in message
news:8B107A64-94A6-452E-BB67-70D4E374E507@microsoft.com...
> 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

Show quoteHide quote
> "un1c0rn" <un1c***@yahoo.com> wrote in message
> news:uDPLbKXoJHA.1172@TK2MSFTNGP04.phx.gbl...
>> 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.
>>
>>
>
Author
17 Mar 2009 5:41 AM
un1c0rn
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