Solved

combine 2 VBS scripts together

Posted on 2015-02-03
6
263 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 500 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 92

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction During my participation as a VBScript contributor at Experts Exchange, one of the most common questions I come across is this: "I have a script that runs against only one computer. How can I make it run against a list of computers in …
This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

707 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