Solved

combine 2 VBS scripts together

Posted on 2015-02-03
6
194 Views
Last Modified: 2015-02-03
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
0
Comment
Question by:paddy086
  • 3
  • 2
6 Comments
 
LVL 35

Accepted Solution

by:
Kimputer earned 500 total points
Comment Utility
Combining 2 seperate VBScripts usually requires NO real knowledge
In this case, it's true. Just copy and paste both codes into a new text file and save it as newcode.vbs and it will run as expected (because there's no overlap in functions/names/variables etc).
But because there's a quit command in the second part, please copy the first part first and add the second part under it.

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

0
 

Author Comment

by:paddy086
Comment Utility
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

0
 

Author Comment

by:paddy086
Comment Utility
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
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 35

Expert Comment

by:Kimputer
Comment Utility
I'm assuming you handing out 0 points to yourself means my answer didn't help you at all?
0
 
LVL 92

Expert Comment

by:Patrick Matthews
Comment Utility
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).
0
 

Author Closing Comment

by:paddy086
Comment Utility
Sorry I taught I accepted your answer . Thanks for the help
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Script to copy or move mouse-selected collection of files plus targets referenced by shortcuts (.lnk) The purpose of this article is to help illuminate the real challenges and options available (where they may exist) for utilizing simple scriptin…
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now