• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 6707
  • Last Modified:

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?
0
Billetkontoret
Asked:
Billetkontoret
  • 3
  • 2
1 Solution
 
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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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
 
BilletkontoretAuthor Commented:
This worked great! You're the man Rob :)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now