Why is WSH giving me the "expected ;" error? - windows

Im trying to get my feet wet with some WSH. I thought it was going to be easy, but it's really a nightmare...
contents of registry.js >
Set shell = WScript.CreateObject('WScript.Shell');
strRegValue = 'HKLM/Software/Microsoft/Windows/CurrentVersion/ProductID';
strPID = shell.RegRead(strRegValue);
WScript.Echo strPID;
This is a code snippet to read a registry value. Maybe you can see what'
s wrong with it because I sure cant!

how about trying this way:
var shell = WScript.CreateObject('WScript.Shell');
// my version of windows does not have the regkey you initially specified
strRegValue = 'HKLM\\Software\\Microsoft\\Windows\\CurrentVersion\\CommonFilesDir';
strPID = shell.RegRead(strRegValue);
WScript.Echo(strPID);

Related

SAP GUIXT - Pass Variable and run script

I would like to create an "input field" in SAP that uses the passed value within a vb script. To give a specific example, I would like to open FBL5N, pass an invoice into a field and view the invoice in VF03. The script to do that is ready and works for a hardcoded value of invoice or thru VBA.
Here is the GUI script part
inputfield (2,35) "inv" (2,45) size=10 name="V_inv"
pushbutton (toolbar) "print_inv" process="InvoiceScript.txt"
using MYINV = "V_inv"
Now, I don't know what to do for the inputscript part. I would like your assistance in this matter. Here is my first attempt:
Screen SAPLSLVC.0500
ApplyGuiScript template="VF03INV.vbs"
Enter
Thank you for your help and let me know if you need any precision.
Here are my sources of inspiration to get the above code :
http://www.synactive.com/tutor_e/lessonia03.html
http://www.synactive.com/docu_e/docia_process2.html
***if its possible to have a version that reads a value in clipboard, that would even be better.
After many attempts here is a solution:
Script(SAPLSLVC.0500.txt):
inputfield (2,35) "inv" (2,45) size=10 name="V_inv"
pushbutton (toolbar) "script" "/OVF03" process="startvf03.txt"
using INV = [V_inv] ' need this when opening new screen
InputScript (startvf03.txt):
parameter INV
Screen SAPMV60A.0101 'this is the VF03 screen
SET F[VBRK-VBELN] "&U[INV]" 'pass invoice # parameter
ApplyGuiScript "C:\guiXT\scripts\VF03INV.vbs"
VBScript (VF03INV.vbs):
inv = session.findById("wnd[0]/usr/ctxtVBRK-VBELN").text
session.findById("wnd[0]/mbar/menu[0]/menu[11]").Select
session.findById("wnd[1]/tbar[0]/btn[37]").press
session.findById("wnd[0]/tbar[0]/okcd").Text = "pdf!"
session.findById("wnd[0]").sendVKey 0
'with some little extra here on how to save a pdf in SAP
'get new strings for locations (specific to my situation)
abc = session.findById("wnd[1]/usr/cntlHTML/shellcont/shell").Browserhandle.locationURL
beg = instr(abc,"C:")
cde = mid(abc,beg,9999)
dest = "C:\111\invoices\" & inv & ".pdf"
'changing from temp to a specific folder
Set FSO = CreateObject("Scripting.FileSystemObject")
FSO.copyfile cde, dest
'close the open file
session.findById("wnd[1]").close
session.findById("wnd[0]").close
Set fso = nothing
*the several If Not IsObject(application) Then you usually see were not necessary, but doesn't hurt to have them.
I hope this helps everyone learn Guixt
Within the VB script with the parameter "template" can you address a GuiXT variable as follows.
for example:
msgbox "&V[V_inv]"

VBScript Error 52 Bad file name or number

I have a VBScript which is used in Avaya CMS to generate a CSV every 3 seconds. This CSV is then read on each change by a node server.
Every now and then it will throw an error (Error 52) and it then requires someone to manually click OK on the prompt and then it continues.
I didn't write the initial script, but I have been trying to fix it so it doesn't throw this error.
As far as I understand, the issue is being caused when the script tries to write to the file when the node server is trying to read the file.
So far I have tried to fix this by making the file read only, then, in the script it makes it writeable, writes to it and makes it read only again.
I thought this had fixed the issue, but I have received Error 52 pop up again and now I am unsure.
Does anyone know if there is a way to get VB/Avaya to ignore the error? I was thinking something like putting On Error Resume Next before the line that writes the file?
I know ignoring errors is not good practice, but in this case, if it does ignore it, it just means the file wont be updated on this loop, but 3 seconds later it will loop again so it should be fine.
Script:
On Error Resume Next
cvsSrv.Reports.ACD = 1
Set Info = cvsSrv.Reports.Reports("Real-Time\Designer\Skill Status")
If Info Is Nothing Then
Else
b = cvsSrv.Reports.CreateReport(Info,Rep)
If b Then
Rep.RefreshInterval = 3
Rep.SetProperty "Split/Skill","5"
Set WshShell = CreateObject("WScript.Shell")
theHTMLLocation = "C:\wamp\www\wallboards\agent_status.csv"
theSleepFile = "C:\wamp\www\wallboards\sleep.vbs"
theTemplateLocation = ""
Set fso = CreateObject("Scripting.FileSystemObject")
Set gfile = fso.GetFile("C:\wamp\www\wallboards\agent_status.csv")
Do While Rep.Window.Caption <> ""
gfile.Attributes = 0
d = Rep.ExportData("C:\wamp\www\wallboards\agent_status.csv", 44, 0, False, True, True)
gfile.Attributes = 1
WshShell.Run "wscript.exe """ & theSleepFile & """", , True
Loop
If Not cvsSrv.Interactive Then cvsSrv.ActiveTasks.Remove Rep.TaskID
Set Rep = Nothing
End If
End If
Set Info = Nothing
P.S - I left out some Parameters at that start of the file which I don't think are relevant, if someone thinks they are I will add them.

Replacing SubString values with the Replace function

The code below looks in the test folder for any files that have not been accessed in over 5 days, if it finds one it assigns mRoot the file path and then whats NOT WORKING is using the Replace method to look inside the mRoot string for the IP and replace it with the new one, I have it show me what mRoot looks like in a pop up just to make sure it changes(or doesn't). I can't seem to get the IP to change. Can anyone help out? I'm very new to VBS so I'm hoping this is obvious (whether it is doable or not). Thanks.
Set oFileSys = WScript.CreateObject("Scripting.FileSystemObject")
sRoot = "\\192.168.1.104\test\"
today = Date
Set aFolder = oFileSys.GetFolder(sRoot)
Set aFiles = aFolder.Files
For Each file in aFiles
FileAccessed = FormatDateTime(file.DateLastAccessed, "2")
If DateDiff("d", FileAccessed, today) > 5 Then
Set objShell = Wscript.CreateObject("Wscript.Shell")
mRoot = file
Call Replace(mRoot,"\\192.168.1.104","\\192.168.1.105")
objShell.Popup mRoot,, "My Popup Dialogue box"
'oFileSys.MoveFile file, mRoot
End If
Next
Try mRoot = Replace(mRoot,"\\192.168.1.104","\\192.168.1.105")

VBScript: Assigning an array(2) via createobject

I'm having a problem converting this VB6 code to VBScript. I'm calling out to a COM object to create an array as EmailAddressType. Here is the working VB6 Code:
'Assign TO: addresses
Dim toAdresses(2) As New EmailAddressType
toAdresses(0).EmailAddress = "someone#whocares.com"
toAdresses(0).RoutingType = "SMTP"
toAdresses(1).EmailAddress = "someoneelse#whocares.com"
toAdresses(1).RoutingType = "SMTP"
email.ToRecipients = toAdresses
I can't seem to figure out how to convert this into VBScript. I've tried the following but just get a Type Mismatch error once I get to the email.ToRecipients = toAdresses
'Assign TO: addresses
dim toAdresses(2)
set toAdresses(0) = createobject("EWS.EWSWebSvc.EmailAddressType")
set toAdresses(1) = createobject("EWS.EWSWebSvc.EmailAddressType")
toAdresses(0).EmailAddress = "someone#whocares.com"
toAdresses(0).RoutingType = "SMTP"
toAdresses(1).EmailAddress = "someoneelse#whocares.com"
toAdresses(1).RoutingType = "SMTP"
email.ToRecipients = toAdresses
Btw this is a COM wrapper of the Exchange Web Services if that helps any.
I think the problem is that the .ToRecipients property wants an array of EmailAddressType while all you can easily get in VBScript is a Variant or array of Variants.
Looks like this API was just not built to be scriptable.
Oddly enough there is an implication it can be used from JScript though: MessageType.ToRecipients Property
I suspect they are rewriting history by gradually editing out any mention of VBScript on MSDN these days though.
Just a guess, try this
toAdresses.EmailAddress = "someone#whocares.com;someoneelse#whocares.com"
toAdresses.RoutingType = "SMTP"
email.ToRecipients = toAdresses
if it doesn't work with the ; try the ,

vbscript for creating registry entries was working, now it isn't. Any ideas?

I have a vbscript that creates a registry entry on a Windows Server 2003 machine. This script has been working fine for about a year now, but recently it just stopped working. I am thinking that a windows update must have changed something, maybe a security setting, whereby this script is no longer permitted to execute. The script uses the following function to create an entry in HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\ for new ODBC connections:
Function CreateRegKey (sComputer, hTree, sKey)
Dim oRegistry
Dim lResult
Set oRegistry = GetObject("winmgmts:{impersonationLevel=impersonate}//" & sComputer & "/root/default:StdRegProv")
lResult = oRegistry.CreateKey(hTree, sKey)
If (lResult = 0) And (Err.Number = 0) Then
CreateRegKey = 0
Else
CreateRegKey = 1
msgbox("Create Key " & sKey & " Failed")
End If
Set oRegistry = Nothing
End Function
This function is called as follows:
Const HKEY_LOCAL_MACHINE = &H80000002
sPath = "SOFTWARE\ODBC\ODBC.INI\" & DataSourceName
'Create ODBC entry
If (0 = CreateRegKey(sComputer, HKEY_LOCAL_MACHINE, sPath)) Then
....
Else
....
End If
Does anyone know of a windows update that could have caused this script to suddenly stop working? The script stops on the following line:
lResult = oRegistry.CreateKey(hTree, sKey)
It does not give an error or anything. It just stops on that line.
Anyone got an idea what is going wrong here and how I could fix it? Thanks.
EDIT: I now get the error number returned by CreateKey. It returns the following:
Err.Number: -2147023533
Err.Description: Cannot start a new logon session with an ID that is already in use
Does anyone know what is causing this and how to work around it? Thanks.
The description for the error code -2147023533 (0x80070553) is:
Cannot start a new logon session with an ID that is already in use.
A search for this code and description reveals:
hotfix KB2283089 for fixing the error,
an assumption that the error is caused by KB979683,
a suggestion to reinstall service packs in order to fix the error.
Give these a try and see if it helps.

Resources