VBscript error code 800A0046 permission denied - vbscript

I am currently trying to create a script that does a bit of remote scripting that triggers a simple messagebox to appear on the screen of a remote user to let a user on a domain network alert every other user that there is a threat in the building. I run the script that is supposed to send the warning to every other users but I get the above mentioned error.
Line: 9
Char: 2
Error: Permission denied
Code: 800A0046
I have tried locating the script in a public network share folder so all users can reach it and have highest permissions to reach it.
I have tested to make sure they can read the pclist file which is just a file with the computer name of every computer in the building that needs to alert.
Dim oFSO, oTSin, oController, oRemote, sComputer
Set oController = CreateObject ("WSHController")
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oTSin = oFSO.OpenTextFile("I:\Public\PCLIST.txt") 'List of PC's
Do Until oTSin.AtEndOfStream
sComputer = oTSin.ReadLine
'Location of script to make run below between ""
Set oRemote = oController.CreateScript("I:\Public\VBS\Alert.vbs", sComputer)
oRemote.Execute
WScript.Echo "Finished script on " & sComputer
Loop
oTSin.Close
WScript.Echo "Finished all computers"
As state above all I really want is just a remote messagebox and maybe a echo char 7 to play over every users computer from like a panic button script. If there is a better way someone please let me know.

https://www.repairwin.com/fixed-permission-denied-800a0046-windows-script-host/
This is a typical error when you try to run a program on a remote computer. It is due to the permissions you have on those machines. You must be administrator of all, even if you are fail many times.
What I do is to send through the Languard application a rar auto-run file to all the machines.
I explain the file you want to run on each machine I send it in rar format but auto-run. When it arrives at that machine the autorun opens giving way to the autorun of for example yours, Alert.vbs
I don't know how to send you here a file, or your Alert.vbs file in rar-exe format.

Related

Monitoring changes on SFTP server with WinSCP and batch

I want to monitor our SFTP to send email to us if a file is added. For now I tried to make a condition with if/else with a batch script, but the batch environment does not accept my condition.
I am new with batch and automation, so what I tried to do is synchronise the SFTP file with a local file in first place and run a batch schedule to try to synchronise again; if it does then it is going to send na email (I did not make the script for the email at the moment and to be honest I do not know how to do so for now), if it did not synchronise then exit script.
Here is my script:
option batch on
option confirm off
open sftp://x#sftp.x/ -privatekey=privateKey.ppk -hostkey="ssh-rsa 2048 x"
option transfer binary
if synchronize local "C:\Users\Administrateur\Desktop\x\x" "/x/x/rx" (
ECHO nouveau fichier ajouter au repertoir
)
else (ECHO aucun nouveau fichier exit
)
Here is the error:
Commande inconnue 'if'.
Add -preview switch to your synchronize command to make it only check for changes, instead of actually synchronizing the files.
Add option failonnomatch on to your script to make the synchronize command report no differences as an error.
option failonnomatch on
synchronize -preview local "C:\Users\Administrateur\Desktop\x\x" "/x/x/rx"
In the actual batch file, check WinSCP exit code to determine, if there are any differences or not. Something like this:
winscp.com /script=script.txt /log=script.log
if errorlevel 1 (
echo Nothing to synchronize or other problem
) else (
echo There are files to synchronize
)
If you want to send an email, see WinSCP guide for Emailing script results.

Telling my backup script in windows to "mount everything that's supposed to be mounted."

I have a backup script that works. I won't put in the entire script, because I don't think it's necessary, but it looks like this:
set backup_dir=R:\__MYBACKUPS
REM *** <<< Right here, I want to have a command that says "Mount everything you know how to mount"
if not exist %backup_dir% (
echo The backup directory does not exist.
echo Making the backup directory %backup_dir%
)
call :get_datetime_stamp
set BACKUPNAME=%backup_dir%\bak%DATEANDTIME%.zip
set default_to_backup="c:\Users\%username%\documents\*.doc*" "c:\Users\%username%\documents\*.csv" "c:\Users\%username%\documents\*.xls*" "c:\Users\%username%\documents\*.pdf" ^
"c:\Users\%username%\documents\*.ppt*" "c:\Users\%username%\documents\*.txt"
set what_to_backup=%default_to_backup% "c:\Users\%username%\etc"
set zip_program="c:\Program Files\winzip\winzip64.exe"
set zip_parameters=-min -a -r
echo EXECUTING THE FOLLOWING BACKUP COMMAND:
echo %zip_program% %zip_parameters% %BACKUPNAME% %what_to_backup%
%zip_program% %zip_parameters% %BACKUPNAME% %what_to_backup%
It works fine, if I mount the R drive. The way I normally do this is when I login I manually go to the explorer window and just click on the R drive ... and that action magically "connects" the R shared network drive. HOWEVER, what I would prefer to do is have the script "mount the drive." I don't want to go in and click all the network drives to connect them. I don't want to specify all the connection garbage. I just want to tell windows, "Mount everything that you already know how to mount."
This is all information that our computer services people have already figured out and configured on all our machines.

VBscript - wscript.echo perfect in Windows 7 - does not work in Window 2012

I've created the following vbs script to show my problem
Wscript.echo "My very first script."
Dim price, vat, net
vat = 16.0
net = 100.0
price = net * (1.0 + vat/100.0)
WScript.Echo "Price: ", price, "US $ Tax: ", vat, "% ", price - net, " US $"
When I run this on my laptop (Windows 7 Professional) everything is beautiful
It displays the first echo message - I click on OK
It then displays the second echo message - again I get to click OK and the script ends
I then upload it to our server (Windows Server 2012 Standard) and
It displays the first Wscript.echo for about 2 seconds then ends.
If I comment out the first message it then displays the second message - again for a couple of seconds then ends.
Can anyone shed any light on this?
It looks like the Timeout
//T:nn Time out in seconds: Maximum time a script is permitted to run
is set to a low value. You can check this assumption by executing
WScript.Echo WScript.Timeout
See the section "Setting a Time-out Value for a Script" in the docs.
You can change the (default) timeout via the command line interface (//T, //S):
cscript
Usage: CScript scriptname.extension [option...] [arguments...]
Options:
//B Batch mode: Suppresses script errors and prompts from displaying
//D Enable Active Debugging
//E:engine Use engine for executing script
//H:CScript Changes the default script host to CScript.exe
//H:WScript Changes the default script host to WScript.exe (default)
//I Interactive mode (default, opposite of //B)
//Job:xxxx Execute a WSF job
//Logo Display logo (default)
//Nologo Prevent logo display: No banner will be shown at execution time
//S Save current command line options for this user
//T:nn Time out in seconds: Maximum time a script is permitted to run
//X Execute script in debugger
//U Use Unicode for redirected I/O from the console
and/or the "Script" properties of the .vbs file.
Before experimenting, however, you should talk to the admin of that server.
(BTW: Whatever you do, don't change your correct WScript.Echo lines to something wrong like MsgBox("Price"))

Scripting SFTP unattended download

I am trying to connect to an SFTP server via software called WinSCP which is a Secure FTP client, I can script it to work by sending keys and doing it in a psuedo unattended mode, but the Server has to have a user logged in to send the keys, I need WinSCP to logon and transfer the files like a service where the console doesn't launch.
I have tried following the Tutorials on the
WinSCP website (for automated/unattended transfers but it gives me errors: Cannot created object, or cannot find library (from the dll file that I have associated with the COM)
The error I get when I run the following code is:
line 13, Char: 2
Could not created object named "WinSCP.SessionOptions"
Code: 80040154
Source: Wscipt.CreateObject
I should also probably mention that I get a similar error about line 21 or 22 about creating the Session object, when I remove the code on line 13 to see if it was the only issue
<job>
<reference object="WinSCP.Session"/>
<script language="VBScript">
Option Explicit
' Setup session options
Dim sessionOptions
Set sessionOptions = WScript.CreateObject("WinSCP.SessionOptions")
With sessionOptions
.Protocol = Protocol_Sftp
.HostName = "host"
.UserName = "username"
.Password = "password"
End With
Dim session
Set session = WScript.CreateObject("WinSCP.Session")
' Connect and Get
session.Open sessionOptions
session.GetFiles("/Fromn/*.*", "C:\testFilesFrom").Check()
' Disconnect, clean up
session.Dispose
</script>
</job>
Has anyone had any experience scripting this kind of job where the server is not logged on and the script can run an SFTP session? Is there somethign I am doing wrong or is this not possible?
WinSCP was made for interactive use. Use PSCP for non-interactive jobs. And I'd strongly recommend using public key authentication instead of password authentication.

Passing values to intermediate (runtime) input prompts of Windows command

I have a windows exe which displays some copyright information, connects to a server and then prompts for input of username and password.
So whenever I run this, I have to wait for the prompt to input username and password.
I generally type ahead the username, , password after the command starts displaying copyright information, but that is a crude way.
Is there a better way to pass parameters to a input prompt of windows command, in a batch file, so that i can avoid typing them always?
P.S. In Linux we do this using the << operator like this
linux_command <<delimiter
inputparamvalue1
inputparamvalue2
delimiter
linux_command will run and on first input prompt, it reads inputparamvalue1 and at next input prompt, it reads inputparamvalue2
In response to James, thanks for the advice on security. I will take care of that.
I tried to implement your solution but that did not work.
These are my files. Please see if you get any hint.
vpn.bat
# echo off
"C:\Program Files (x86)\Cisco\Cisco AnyConnect VPN Client\vpncli.exe" connect "mycompanyvpnsite.com"
login.txt
myusername
mypassword
startvpn.bat
#ECHO OFF
CALL vpn.bat < login.txt
ECHO I'm back!
Result
D:\>startvpn.bat
Cisco AnyConnect VPN Client (version 2.5.6005) .
Copyright (c) 2004 - 2010 Cisco Systems, Inc.
All Rights Reserved.
>> state: Disconnected
>> notice: Ready to connect.
>> registered with local VPN subsystem.
>> state: Disconnected
>> notice: Ready to connect.
VPN> >> contacting host (mycompanyvpnsite.com) for login information...
>> notice: Contacting mycompanyvpnsite.com.
VPN>
>> Please enter your username and password.
Username: [myusername] Password:
Username myusername which it is showing is cached from my previous manual logins. So it appears that this run did not take any values from the login.txt.
If I had executed my vpn.bat alone without any params, i get prompt like this
VPN>
>> Please enter your username and password.
Username: [myusername] <i press enter to take the cached value>
Password: ******** <i enter password and press enter>
and it connects.
The vpn client does not have privilege to specify password on command line, that's why I am trying this way.
i've got a working code! It's similar to James K's but with a few bugs hammered out. Once again, I want to reiterate that this is rather insecure because it exposes your password in an unencrypted setting. that being said:
'Anyconnect login script
Dim oShell
Set oShell = WScript.CreateObject("WScript.Shell")
' rather clunky way of selecting the correct directory - open to suggestion
oShell.Run "cmd /k cd %PROGRAMFILES(x86)%\Cisco & cd Cisco* & vpncli.exe connect MYCOMPANYVPN.COM"
' sleep of 100 neccessary or else it opens multiple cmd windows
Wscript.sleep 100
' activate correct window
oShell.AppActivate "Connect"
' optional ipsec Identifier used for multiple VPN profiles on the same server
'(if you don't have one, just comment this out)
oShell.SendKeys "IPSECID{ENTER}"
' Send Username and Password to Active Window.
oShell.SendKeys "USERNAME{ENTER}"
oShell.SendKeys "USERPASSSWORD{ENTER}"
oShell.SendKeys "exit{ENTER}"
Good luck!
Saving your username and password in a file to automate login processes is a very bad idea and invalidates any security that requiring usernames and passwords supplies because anyone who get's electronic or physical access to your computer will have access to your plain-text username and password.
That said, in DOS / Windows Command Prompt you will need an extra file containing your username and password like so:
LOGIN.TXT
MyUserName
MyPassword
Then pipe that file into your command like this:
#ECHO OFF
CALL Command_Or_Batch < login.txt
ECHO I'm back!
This will act just as if you were at the console and typed MyUserName[ENTER] MyPassword[ENTER].
login.txt is just a plain vanilla text file, and does not need the .txt extension, or any extension at all for that matter.
The CALL statement is only necessary when launching another batch file, if you want it to, when finished, continue executing in the original calling batch file. Using CALL makes no difference when calling an executable (anything other than a batch file).
EDIT: As per your comments, I believe that you need to do this to get it to work:
# echo off
"C:\Program Files (x86)\Cisco\Cisco AnyConnect VPN Client\vpncli.exe" connect "mycompanyvpnsite.com" < login.txt
In this case you redirect to your vpncli.exe, but I believe that this will have the side-effect of making vpncli.exe ONLY accept input from login.txt, and not from the keyboard at all until vpncli.exe exits. Meaning that you'll need to automate (store in login.txt) all the stuff you would normally need to type in. This should not be a problem unless you need to manually interact with vpncli.exe later on.
EDIT: Since vpncli.exe seems to be clearing the buffer before reading any keystrokes, I suggest that possibly using VBS might get you where you're wanting to go.
VPN.VBS
'VBScript Example
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "C:\Program Files (x86)\Cisco\Cisco AnyConnect VPN Client\vpncli.exe connect mycompanyvpnsite.com"
' You need to know the name of the window, It should be in the upper left corner
' I'm guessing that it will be the filename of the executible
WshShell.AppActivate "vpncli.exe"
' Send Username and Password to Active Window.
WshShell.SendKeys "MyUserName{ENTER}"
WshShell.SendKeys "MyPassword{ENTER}"
But I can't be sure. I've had problems testing this, though I'm just bouncing back and forth between batch files and VBS scripts.
Though I do know if you replace the WshShell.Run and WshShell.AppActivate with the following two lines that...
WshShell.Run "%windir%\notepad.exe"
WshShell.AppActivate "Notepad"
...notepad will open and the following two lines will appear:
MyUserName
MyPassword
If this doesn't work for you, I'm thinking about deleting this answer entirely since it only contains suggestions that haven't worked.

Resources