ASP.Net: Run vbs script on client machine

HI!

Need some help with a web page, I have created a simple web page with one button,
When I press this button I need to execute a vbs script that is located on the sever, but I need it to be executed on the client side.

The script will install a printer on the client.

How do I do that?

Here is the vbs script that I need to run on the client, the script works if I execute it on the client.
So when the user pressing the button on the webpage I like to run this vbs script on the client so the printer will be installed.

Dim domainUser
Dim userPass
Dim printerName
Dim mapName
 
'================================
'      Set Script Variables
'================================
Set WShell = WScript.CreateObject("Wscript.Shell")
Set FSO = CreateObject("Scripting.FileSystemObject")
Set Net = WScript.CreateObject("WScript.Network")
 
netWorkDrive = "Y:"
printerPath = "\\awsrv\printers$"
domainUser = "aw.local\printer"
userPass = "gdsjhfgf"
printerName = "\\awsrv\epson al-c900"
 
'================================
'     Finish up the Script
'================================
SubNetMap()
SubAddPrinter()
SubRemoveNetMap()
 
'-------------------------------------------------------------------------------
'
' Sub Functions
'
'-------------------------------------------------------------------------------
'================================
'     Map printer Folder
'================================
Sub SubNetMap()
     mapName = netWorkDrive & printerPath
    
    If Not FSO.FolderExists(mapName) Then
          Net.MapNetworkDrive netWorkDrive, printerPath, , domainUser, userPass
    End If
End Sub
 
 
'================================
'    Add printer
'================================
Sub SubAddPrinter()
    Net.AddWindowsPrinterConnection printerName
End Sub
 
'================================
'    Delete Printer Folder
'================================
Sub SubRemoveNetMap()
   Net.RemoveNetworkDrive netWorkDrive
End Sub

Open in new window

LVL 1
AWestEngAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

oobaylyCommented:
You won't be able to get the browser to execute the script without any user interaction, that would be a massive security loophole.
The best you can do it to get the user to download the script, and execute it themselves.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AWestEngAuthor Commented:
ok but I can open some type of dialog that ask if the user wants to ""install" the printer, but how do I do that?
0
ITHelper80Commented:
Hi,
Try placing the below code in the head of your page and then add this to your button control.
OnClientClick="MapPrinter()"/
<script type="text/vbscript" language="vbscript"  runat="server">
    Sub MapPrinter()
        Dim domainUser
        Dim userPass
        Dim printerName
        Dim mapName
 
        '================================
        '      Set Script Variables
        '================================
        WShell = WScript.CreateObject("Wscript.Shell")
        FSO = CreateObject("Scripting.FileSystemObject")
        Net = WScript.CreateObject("WScript.Network")
 
        netWorkDrive = "Y:"
        printerPath = "\\awsrv\printers$"
        domainUser = "aw.local\printer"
        userPass = "gdsjhfgf"
        printerName = "\\awsrv\epson al-c900"
 
        '================================
        '     Finish up the Script
        '================================
        SubNetMap()
        SubAddPrinter()
        SubRemoveNetMap()
 
        '-------------------------------------------------------------------------------
        '
        ' Sub Functions
        '
        '-------------------------------------------------------------------------------
        '================================
        '     Map printer Folder
        '================================
Sub SubNetMap()
        mapName = netWorkDrive & printerPath
    
        If Not FSO.FolderExists(mapName) Then
            Net.MapNetworkDrive(netWorkDrive, printerPath, , domainUser, userPass)
        End If
    End Sub
 
 
    '================================
    '    Add printer
    '================================
    Sub SubAddPrinter()
        Net.AddWindowsPrinterConnection(printerName)
    End Sub
 
    '================================
    '    Delete Printer Folder
    '================================
    Sub SubRemoveNetMap()
        Net.RemoveNetworkDrive(netWorkDrive)
    End Sub
 
    End Sub
    
</script>

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.