Link to home
Start Free TrialLog in
Avatar of paddy086
paddy086Flag for Ireland

asked on

combine 2 VBS scripts together

Hi  

I have 2 individual vbs scripts that both work. one makes mapped drives and the second one makes a short cut to a office 365 login
I need to combine both scripts into the one vbs script file.

Mapped drive .vbs
Set objNetwork = CreateObject("WScript.Network")
objNetwork.MapNetworkDrive "S:" , "\\Prometheus\Student_Share"
objNetwork.MapNetworkDrive "T:" , "\\Prometheus\Teacher_Share"
objNetwork.MapNetworkDrive "x:" , "\\Prometheus\Folder Redirection"

Open in new window


Shortcut Office 365 .vbs
' CreateShortCut.vbs - Create a Desktop Shortcut.
' VBScript to create .lnk file

' ----------------------------------------------------------' 
Option Explicit
Dim objShell, objDesktop, objLink
Dim strAppPath, strWorkDir, strIconPath

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

strWorkDir ="C:\Documents and Settings\%username%\Desktop"
strAppPath = "https://login.microsoftonline.com/"
strIconPath = "%SystemRoot%\system32\SHELL32.dll,27"

Set objShell = CreateObject("WScript.Shell")
objDesktop = objShell.SpecialFolders("Desktop")
Set objLink = objShell.CreateShortcut(objDesktop & "\Microsoft 365 Login.lnk")

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

objLink.Description = "Microsoft 365 Login"
objLink.HotKey = "CTRL+SHIFT+X"
objLink.IconLocation = strIconPath 
objLink.TargetPath = strAppPath
objLink.WindowStyle = 3
objLink.WorkingDirectory = strWorkDir
objLink.Save


WScript.Quit

' End of creating a desktop shortcut

Open in new window



Thanks
ASKER CERTIFIED SOLUTION
Avatar of Kimputer
Kimputer

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of paddy086

ASKER

So I have done what you said but I get this error on.

Line:10
Char:1
Error: Expected statement
Code: 800A0400
Source: Microsoft VBScript compilation error

Set objNetwork = CreateObject("WScript.Network")
objNetwork.MapNetworkDrive "S:" , "\\Prometheus\Student_Share"
objNetwork.MapNetworkDrive "T:" , "\\Prometheus\Teacher_Share"
objNetwork.MapNetworkDrive "x:" , "\\Prometheus\Folder Redirection"

' CreateShortCut.vbs - Create a Desktop Shortcut.
' VBScript to create .lnk file

' ----------------------------------------------------------' 
Option Explicit
Dim objShell, objDesktop, objLink
Dim strAppPath, strWorkDir, strIconPath

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

strWorkDir ="C:\Documents and Settings\%username%\Desktop"
strAppPath = "https://login.microsoftonline.com/"
strIconPath = "%SystemRoot%\system32\SHELL32.dll,27"

Set objShell = CreateObject("WScript.Shell")
objDesktop = objShell.SpecialFolders("Desktop")
Set objLink = objShell.CreateShortcut(objDesktop & "\Microsoft 365 Login.lnk")

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

objLink.Description = "Microsoft 365 Login"
objLink.HotKey = "CTRL+SHIFT+X"
objLink.IconLocation = strIconPath 
objLink.TargetPath = strAppPath
objLink.WindowStyle = 3
objLink.WorkingDirectory = strWorkDir
objLink.Save



WScript.Quit

' End of creating a desktop shortcut

Open in new window

I've requested that this question be closed as follows:

Accepted answer: 0 points for paddy086's comment #a40586550

for the following reason:

Thanks I got it working by removing
Option Explicit
Avatar of Kimputer
Kimputer

I'm assuming you handing out 0 points to yourself means my answer didn't help you at all?
Don't get rid of Option Explicit: it is actually there to help you!

Instead, move it up to the top line of the combined script.  Option Explicit, when used, must be the first line of actual code in the script file (although you can have comments and/or white space before it).
Sorry I taught I accepted your answer . Thanks for the help