VBS-script: call a .vbs-file within a vbs-script

Hi alle, I have this vbs-script in which I want to call another vbs-script at the top:

Option Explicit
Dim objNetwork, objUser, CurrentUser
Dim strGroup

' Her defineres grupperne
Const ITdrift = "cn=itdrift"
Const ITPrinter = "cn=it-printer"
Const Hotelafd = "cn=hotelafd"
Const Aarhus = "cn=århus"
Const Bogholderi = "cn=bogholderiet"
Const Users_Group = "cn=users"
Const Billetafd = "cn=billetafdelingen"
Const RBU = "cn=rbu"

' Opret objekter mv
Set objNetwork = CreateObject("WScript.Network")
Set objUser = CreateObject("ADSystemInfo")
Set CurrentUser = GetObject("LDAP://" & objUser.UserName)
strGroup = LCase(Join(CurrentUser.MemberOf))

' ****************************************************************************************
' Hvis medlem af ITdrift, add printers
If InStr(strGroup, lcase(ITdrift)) Then
WScript.Echo "Du er medlem af ITdrift - installerer dine printere..."
Set objNetwork = CreateObject("WScript.Network")
objNetwork.AddWindowsPrinterConnection "\\omada\HP LaserJet 2300 Series PS"
objNetwork.AddWindowsPrinterConnection "\\omada\Canon CLC-iR C3200 Billetkontoret"
objNetwork.AddWindowsPrinterConnection "\\omada\hp color LaserJet 2550 PS"
objNetwork.AddWindowsPrinterConnection "\\omada\HP LaserJet 2400 Series PS"
' objNetwork.SetDefaultPrinter "\\omada\HP LaserJet 2400 Series PS"
' objNetwork.MapNetworkDrive "h:", "\\Server\Users\" _

ElseIf InStr(strGroup, lcase(Users_Group)) Then
' WScript.Echo " Du er ikke medlem af nogen gruppe med printere tilknyttet "

End If
' ****************************************************************************************
' Hvis medlem af Hotelafd, add printers
If InStr(strGroup, lcase(Hotelafd)) Then
WScript.Echo "Du er medlem af Hotelafd - installerer dine printere..."
Set objNetwork = CreateObject("WScript.Network")
objNetwork.AddWindowsPrinterConnection "\\omada\hp color LaserJet 2550 PS"
objNetwork.AddWindowsPrinterConnection "\\omada\HP LaserJet 2400 Series PS"
' objNetwork.SetDefaultPrinter "\\omada\HP LaserJet 2400 Series PS"

ElseIf InStr(strGroup, lcase(Hotelafd)) Then
' WScript.Echo " Du er ikke medlem af nogen gruppe med printere tilknyttet "

End If
' ****************************************************************************************
' Hvis medlem af Aarhus, add printers
If InStr(strGroup, lcase(Aarhus)) Then
WScript.Echo "Du er medlem af Aarhus - installerer dine printere..."
Set objNetwork = CreateObject("WScript.Network")
objNetwork.AddWindowsPrinterConnection "\\aar-print\HP Color LaserJet 3600"
objNetwork.AddWindowsPrinterConnection "\\aar-print\HP LaserJet 4200 PCL 6"
objNetwork.AddWindowsPrinterConnection "\\aar-print\HP LaserJet 4200 PCL5e"
' objNetwork.SetDefaultPrinter "\\aar-print\HP LaserJet 4200 PCL5e"
objNetwork.MapNetworkDrive "t:", "\\aar-print\coupons\" _

ElseIf InStr(strGroup, lcase(Aarhus)) Then
' WScript.Echo " Du er ikke medlem af nogen gruppe med printere tilknyttet "

End If
' ****************************************************************************************
' Hvis medlem af Billetafdelingen, add printers
If InStr(strGroup, lcase(Billetafd)) Then
WScript.Echo "Du er medlem af Billetafdelingen - installerer dine printere..."
Set objNetwork = CreateObject("WScript.Network")
objNetwork.AddWindowsPrinterConnection "\\omada\Billetafd_1 PCL5"
' objNetwork.SetDefaultPrinter "\\omada\Billetafd_1 PCL5"

ElseIf InStr(strGroup, lcase(Aarhus)) Then
' WScript.Echo " Du er ikke medlem af nogen gruppe med printere tilknyttet "

End If
' ****************************************************************************************
' Hvis medlem af Bogholderiet, add printers
If InStr(strGroup, lcase(Bogholderi)) Then
WScript.Echo "Du er medlem af Bogholderiet - installerer dine printere..."
Set objNetwork = CreateObject("WScript.Network")
objNetwork.AddWindowsPrinterConnection "\\omada\Bogholderiet PCL 5"
objNetwork.AddWindowsPrinterConnection "\\omada\Bogholderiet PCL 6"
objNetwork.SetDefaultPrinter "\\omada\Bogholderiet PCL 5"

ElseIf InStr(strGroup, lcase(Aarhus)) Then
' WScript.Echo " Du er ikke medlem af nogen gruppe med printere tilknyttet "

End If
' ****************************************************************************************
' Hvis medlem af RBU, add printers
If InStr(strGroup, lcase(RBU)) Then
WScript.Echo "Du er medlem af RBU - installerer dine printere..."
Set objNetwork = CreateObject("WScript.Network")
objNetwork.AddWindowsPrinterConnection "\\omada\RBU"
' objNetwork.SetDefaultPrinter "\\omada\RBU"

ElseIf InStr(strGroup, lcase(Aarhus)) Then
' WScript.Echo " Du er ikke medlem af nogen gruppe med printere tilknyttet "

End If
' ****************************************************************************************
' Hvis medlem af ITPrinter, add printers
If InStr(strGroup, lcase(ITPrinter)) Then
WScript.Echo "Du er medlem af ITPrinter-gruppen (HP 2400-printeren i det lille printerrum på 6.sal) - installerer..."
Set objNetwork = CreateObject("WScript.Network")
objNetwork.AddWindowsPrinterConnection "\\omada\IT-Printer"
objNetwork.SetDefaultPrinter "\\omada\IT-Printer"

ElseIf InStr(strGroup, lcase(Aarhus)) Then
' WScript.Echo " Du er ikke medlem af nogen gruppe med printere tilknyttet "

End If
' ****************************************************************************************

WScript.Quit


How do I do that?
LVL 2
BilletkontoretAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jindalankushCommented:
just calling scripts name
E.g
call wscripts2
0
BilletkontoretAuthor Commented:
ehm - I know nothing about this but putting this in an empty .vbs-file fails: call wscripts2.
0
RobSampsonCommented:
Hi, at the top, put this:

Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
strScriptName = "myScript.vbs"
strScriptName = objFSO.GetFile(strScriptName).ShortPath
objShell.Run "wscript " & strScriptName, 1, True
Set objShell = Nothing
Set objFSO = Nothing


Regards,

Rob.
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

BilletkontoretAuthor Commented:
I have this at the very top of my script now:

Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
strScriptName = "slet-printere.vbs"
strScriptName = objFSO.GetFile(strScriptName).ShortPath
objShell.Run "wscript " & strScriptName, 1, True
Set objShell = Nothing
Set objFSO = Nothing

Option Explicit
Dim objNetwork, objUser, CurrentUser
Dim strGroup

' Her defineres grupperne
Const ITdrift = "cn=itdrift"
Const ITPrinter = "cn=it-printer"
---------------------------------------------------------
I get a compilation-error:
Expected statement, line 10 char 1.
This is line 10: Dim objNetwork, objUser, CurrentUser

0
RobSampsonCommented:
OK, slightly re-arranged, try this....I think the Option Explicit needs to be the first statement, if it exists:

Option Explicit
Dim objShell, objFSO, strScriptName

Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
strScriptName = "slet-printere.vbs"
strScriptName = objFSO.GetFile(strScriptName).ShortPath
objShell.Run "wscript " & strScriptName, 1, True
Set objShell = Nothing
Set objFSO = Nothing

Dim objNetwork, objUser, CurrentUser
Dim strGroup

' Her defineres grupperne
Const ITdrift = "cn=itdrift"
Const ITPrinter = "cn=it-printer"
---------------------------------------------------------


Regards,

Rob.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
BilletkontoretAuthor Commented:
This worked great! You're the man Rob :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.