Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

combine 2 VBS scripts together

Posted on 2015-02-03
6
Medium Priority
?
318 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 36

Accepted Solution

by:
Kimputer earned 2000 total points
ID: 40586528
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
ID: 40586550
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
ID: 40586712
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 36

Expert Comment

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

Expert Comment

by:Patrick Matthews
ID: 40587442
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
ID: 40587475
Sorry I taught I accepted your answer . Thanks for the help
0

Featured Post

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article we want to have a look at the directory attributes which are used by Microsoft to store the so called Security Identifiers (SID). These SIDs plays an important role in delegating and granting permissions and in authentication of trus…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

609 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