I am fairly new at .VBS and I've hit a bump. I'm trying to create a script that will allow me to automatically create a hotspot from any laptop, that the program is opened on. The bump I hit is that I cant find a way to automatically obtain the username#domain from command prompt and turned into a variable to be later injected into the coding. This is what I have so far:
msgbox("Close Me And Run As Administrator")
name=inputbox("Set SSID (WiFi Name)")
pass=inputbox("Password For WiFi")
strCmd="net wlan set hostnetwork mode=allow ssid=name key=pass"
set objShell=CrateObject("wscript.shell")
objShell.Run runas /user: "strCmd" 'this is why I need to figure out how to store and inject those variables
strCMd="net wlan set hostnetwork mode=allow ssid=name key=pass"
set objShell=CrateObject("wscript.shell")
objShell.Run runas /user: "strCMd"
and then the rest is just msgbox telling them how to finish if they want to set up file sharing (i.e. xbox, ps3 or other computers on network)
A little search on Google and I got this: http://www.robvanderwoude.com/vbstech_network_names_domain.php
Related
Today I do e.g.:
Set WshShell = CreateObject("WScript.Shell")
Call WshShell.Run("psexec -u administrator -p pw1234 cmd /c netsh interface ip show address > C:\Output.txt", 2, True)
This works, but the command prompt window is always visible for a short time.
I've been searching the web and I've tried everything I could possibly think of to hide/minimize this window, but unfortunately without success.
So I'm afraid that there's no way to run psexec in a hidden/minimized window.
But is there perhaps another way to execute a privilege command in VBScript with a normal user where no command prompt window is visible?
I am working on a VBScript where it activates an application, sends a password to that application and minimizes the application. My script fails sending the keys. The application does not get the password, but when I double-click on the script it receives the password and minimizes. I don't know where the error is.
It's called like this:
InitliszeUSb.bat:
pause
START %myDrive%"RunSanDiskSecureAccess_Win.exe"
pushd %~dp0
ping 10.10.10.10 -n 1 -w 10000 >nul
start /b "" cscript "D:\min.vbs"
Min.vbs:
Option Explicit
Dim oSHL : Set oSHL = CreateObject("WScript.Shell")
oSHL.AppActivate "SanDisk SecureAccess"
oSHL.SendKeys "pass1_word~" 'Enters Password
WScript.Sleep(3000)
oSHL.SendKeys "% n" 'Minimises the window
WScript.Quit
In Windows 7, I experienced issues when using SendKeys to send keys to other apps (the way like you do), when SendKeys is not running in elevated process. Sometimes the macro/script works 100%, sometimes it looks like keystrokes are getting lost. The only way around I found for that was running sender application (or script) elevated (i.e. "As Administrator").
I want to launch an exe file of my product (C:\ClassConnect\class_server.cmd) on user login.
I tried 2 solutions ( but nothing seems to work)
Solution 1 : ( Added Startup Shortcut )
It asks the user for UAC dialog, which obviously my users will not accept as its a spy app.
Solution 2 : ( Added batch to windows scheduler so that it runs for any user)
It runs fine with the administrator account but fails for other users.
Moreover I am not able to view scheduled tasks on other users
Please help. ( I want the batch to run on startup for all users on my machine)
I would recommend you to put your class_server.cmd file in the alluser start-up folder:
C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup
Or call your .cmd file via shortcut and runas in the start-up folder to solve the UAC problem. Follow this documentation: http://www.howtogeek.com/124087/how-to-create-a-shortcut-that-lets-a-standard-user-run-an-application-as-administrator/
After struggling my head for so many days, I finally found the answer for running the program as admin
I wrote the following batch file to run one of my system program in admin mode without UAC Popup( it auto Enters the admin password )
I wrote a batch file run.bat with following content => it then executes a vb script which waits for 5 second and keys in the password.
================run.bat Start========================
set USER_NAME="administrator"
set PASSWORD="test"
set PROGRAM_NAME="C:\\ClassConnect\\class_student.bat"
set "cm=cscript /B /nologo runas4.vbs %PASSWORD%"
%cm%
runas /profile /env /user:%USER_NAME% "%PROGRAM_NAME%"
================run.bat End========================
================runas4.vbs Start========================
Set objArgs = Wscript.Arguments
password=objArgs(0)
set WshShell = WScript.CreateObject("Wscript.Shell")
WScript.Sleep 5000
bWindowFound = WshShell.AppActivate("ClassConnect_Teacher")
WScript.Sleep 500
WshShell.SendKeys password
WshShell.SendKeys "{ENTER}"
set WshShell = nothing
================runas4.vbs End========================
The above script waits for 5 second and then enters the password for runas command thus I am able to run the script in admin mode.
If you are not sure about your access rights, download the isadmin.exe from internet.
if you do not have admin access on the system , activate the default disabled Administrator account. You can activate the account by using
net user administrator /active:yes
For resetting the default administrator password use:
net user administrator *
I'm just a lurker and wondering if I can create a vbscript that can run command prompt together with the other command that I want to type in command prompt.
Here's what I want to do:
I want to create a wifi hotspot using command prompt with this command;
`netsh wlan set hostednetwork mode=allow ssid=NAME key=PASSWORD
netsh wlan start hostednetwork'
and another thing, can anyone helped me how can i share my network using command prompt to make my laptop wifi hotspot?
You want the "Shell" object to run commands:
strText="netsh wlan set hostednetwork mode=allow ssid=NAME key=PASSWORD"
Set shll = Wscript.CreateObject("Wscript.Shell")
Return = shll.Run(strText, 1, TRUE)
you can add as many "shll.run" commands as you need to - the TRUE flag above will make VBScript wait for the command to finish before continuing the script.
You would be better off looking at Powershell for sharing network connections.
I am logging into the server as Administrator to winserver2008.
I created a script called: vbscript.vbs
The purpose of this script is to auto login to linux via putty, then perform command line task.
Dim Shell
Set Shell = CreateObject("WScript.Shell")
output = Shell.Run("C:\putty.exe 1.2.3.4 9321")
wscript.sleep(500)
Shell.Sendkeys "root" & VBCrLf
wscript.sleep(30)
Shell.Sendkeys "password" & VBCrLf
wscript.sleep(30)
When I manually click on vbscript.vbs to execute it, vbscript will fill in root and password to putty.
When I use windows scheduler call to vbscript.vbs to execute it, vbscript won't fill in root and password to putty.
I suspect some permission issue.
I already set putty.exe to run as administrator, allow administrator, administrators group permission for it, but still fail to work when call via windows scheduler.
=====
I just tried with the second scenario, send 2 to the windows calculator, fail too..
testcalc.vbs
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run "Calc.exe"
objShell.AppActivate "Calculator"
objShell.SendKeys "2"
Give up on trying to get SendKeys to work from a scheduled task, it's not going to happen. Instead simply pass the login and password on the command line:
output = Shell.Run("C:\putty.exe -l root -pw password 1.2.3.4 9321")
Alternatively do it with a session file and use -load.
If you are then going to execute commands over this connection then I believe you actually want plink rather than putty.