Open shared folder with different credentials in vbscript - vbscript

Iam using vbscripr to open network folder like
Set shell = wscript.CreateObject("Shell.Application")
shell.Open "\\xxxxxxxxxxx\c$"
I don't have access for the drive "yyyy" but i have the UN and PW. how can i use the credentials in vbscript to open the shared folder.
Thanks

The short answer is you cannot do this. The "open" method does not allow you to pass a parameter other than the directory name and the "Shell.Application" object doesn't have a method to do it either.
Source:
Open Method:
http://msdn.microsoft.com/en-us/library/windows/desktop/bb774086(v=vs.85).aspx
List of Methods for Shell.Application:
http://msdn.microsoft.com/en-us/library/windows/desktop/bb774094(v=vs.85).aspx
A possible workaround to this issue would be to relaunch your script via the command prompt and call something like PSEXEC. Something like this:
Dim oShell
Set oShell = WScript.CreateObject ("WScript.Shell")
oShell.run "%COMSPEC% /C psexec -u domain\user -p password -accepteula cscript.exe c:\path\yourscript.vbs"
Set oShell = Nothing
You can download PSEXEC from here:
http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx

As awful as it is I use sendkeys (after a little wscript.sleep 2000)...
`...
Set objFolder = objFSO.GetFolder(strShare) 'check access
If Err.Number <> 0 Then
WScript.Sleep 2000
objShell.SendKeys "username" 'username
objShell.SendKeys "{TAB}"
objShell.SendKeys "password" 'password
objShell.SendKeys "{Tab}"
objShell.SendKeys " " 'save credentials
ObjShell.SendKeys "{Tab}"
ObjShell.SendKeys "{ENTER}"
End If
Set ObjShell = Nothing
...`

Related

Object required:'WshShell'

Hey Everyone I'm trying to make a simple VBS script and I keep getting Error bject required:'WshShell'
Here is the script
CreateObject("WScript.Shell").Run "C:\DEXIS\DEXsync.exe"
WScript.Sleep 1000
WshShell.SendKeys "{ENTER}"
WScript.Quit()
I have also attached the error message. can someone please help I feel like i'm taking crazy pills
error message
You'll need to set that WshShell variable you are using to a new Wscript.Shell object. Try something like this instead:
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run "C:\DEXIS\DEXsync.exe"
WScript.Sleep 1000
WshShell.SendKeys "{ENTER}"
WScript.Quit()

vbscript auto form submition failed

Hi I have the following vb script that opens a Program, then clicks an ok button on a pop up message then enters a form with server name, user name and password and then clicks submit. The script works well as i have it running as a scheduled logon script.
However if the user opens another window as this script is running then the script fails. I need o make the script a bit more intelligent by focusing on the correct window. Please help.
Dim objShell
Set objShell = WScript.CreateObject( "WScript.Shell" )
objShell.Run("""C:\Program Files (x86)\SNS EVO ShareBrowser\Client\evo ShareBrowser.exe""")
WScript.Sleep 1000
objShell.SendKeys "{ENTER}"
WScript.Sleep 1000
objShell.SendKeys "abc"
objShell.SendKeys "{TAB}"
objShell.SendKeys "user"
objShell.SendKeys "{TAB}"
objShell.SendKeys "password"
objShell.SendKeys "{ENTER}"
wscript.Quit

How to hit Enter in cmd from VBSCript

Trying to run few Commands from VBScript
Dim objShell
Set objShell = WScript.CreateObject ("WScript.shell")
objShell.run "cmd /c cd C:\Script & lcm_cli.bat -lcmproperty C:\LCMBiar_Import.property"
The Second command lcm_cli.bat -lcmproperty C:\LCMBiar_Import.property requires me to hit enter to complete its execution. Any idea how to do that through VBScript.
Tried giving
objShell.Sleep(1000)
objShell.SendKeys("{ENTER}")
but nothing happens. Still waits for manual hit of enter!
The solution is:
WshShell.SendKeys "{ENTER}"

How can I make a batch file or script file which will be able to auto login into any router with provided password

How can I make a bat file or script file which will be able to auto login into any router with provided password...
I tried a script code but this is not taking password and asking to enter in coming cmd window..
Please help either in this vb script or any other solution ..
Set cloner = CreateObject("WScript.Shell")
cloner.run"cmd"
WScript.Sleep 500
cloner.SendKeys "telnet 0.0.0.0"
cloner.SendKeys ("{Enter}")
WScript.Sleep 500
cloner.SendKeys "My password"
cloner.SendKeys ("{Enter}")
WScript.Sleep 5000
Please edit your question and add the tag Vbscript
As he said Markus W Mahlberg in the comment
Every freaking router has either it's own web interface, with it's own
naming on input fields and such, some have no web interface at all,
some are administered via telnet, others via SSH.
So you can give a try at this vbscript and i hope that you have a chance; It will work for you ;)
RebootMyRouter.vbs I use it to reboot my router via Telnet
Option Explicit
Dim MyHote,MyLogin,MyPassword
MyHote = "192.168.1.1" 'Change this line to your host
MyLogin = "admin"
MyPassword = "admin" 'Change this line with your password
Call Reboot_MyRouter(MyHote,MyLogin,MyPassword)
'******************************************************************************
Sub Reboot_MyRouter(MyHote,MyLogin,MyPassword)
Dim ws,Command,StrCommand,Execution
Set ws = CreateObject("wscript.shell")
Command = "Telnet " & MyHote
StrCommand = "cmd /c color 9B & mode con cols=65 lines=10 & "& Command &""
Execution = ws.run(StrCommand,1,False)
wscript.sleep 500
ws.AppActivate Command
ws.sendkeys MyLogin
ws.sendkeys "{enter}"
wscript.sleep 1000
ws.sendkeys MyPassword
ws.sendkeys "{enter}"
End Sub
'******************************************************************************

Simulate Enter Key

Is there a way to simulate the enter key in VBScript? Ex.:
set shl = createobject("wscript.shell")
shl.sendkeys "SIMULATED ENTER"
try {ENTER}, ie
shl.SendKeys "{ENTER}"
here's my reference http://www.computerperformance.co.uk/ezine/ezine120.htm
The vbscript to press enter key working!
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.SendKeys "{ENTER}"

Resources