VBS Script for listing out Outlook Profile Info - vbscript

I have found some code on the Internet for listing out Outlook Profile Info and I would like to it, but it gives the error: Type mismatch:'[string: "A"]', at line 74 (code 800A000D). I don't know why it's not working.
Here is the code:
Option Explicit
Const HKEY_CURRENT_USER = &H80000001
Const r_PSTGuidLocation = "01023d00"
Const r_MasterConfig = "01023d0e"
Const r_PSTCheckFile = "00033009"
Const r_PSTFile = "001f6700"
Const r_keyMaster = "9207f3e0a3b11019908b08002b2a56c2"
Const r_ProfilesRoot = "Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles"
Const r_DefaultProfileString = "DefaultProfile"
Dim oReg:Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
Dim arrSubKeys, subkey, strValue, i, pstFile, arrPSTs, DefaultProfileName
oReg.GetStringValue HKEY_CURRENT_USER,r_ProfilesRoot,r_DefaultProfileString,DefaultProfileName
GetPSTsForProfile(DefaultProfileName)
'_____________________________________________________________________________________________________________________________
Function GetPSTsForProfile(p_profileName)
Dim strHexNumber, strPSTGuid, strFoundPST
oReg.GetBinaryValue HKEY_CURRENT_USER,r_ProfilesRoot & "\" & p_profileName & "\" & r_keyMaster,r_MasterConfig,strValue
If IsUsableArray (strValue) Then
For Each i In strValue
If Len(Hex(i)) = 1 Then
strHexNumber = CInt("0") & Hex(i)
Else
strHexNumber = Hex(i)
End If
strPSTGuid = strPSTGuid + strHexNumber
If Len(strPSTGuid) = 32 Then
If IsAPST(r_ProfilesRoot & "\" & p_profileName & "\" & strPSTGuid) Then
Wscript.Echo PSTFileName(r_ProfilesRoot & "\" & p_profileName & "\" & _
PSTlocation(r_ProfilesRoot & "\" & p_profileName & "\" & strPSTGuid))
End If
strPSTGuid = ""
End If
Next
End If
End Function
'______________
'_____________________________________________________________________________________________________________________________
Function GetSize(zFile)
Dim objFSO:Set objFSO = CreateObject("Scripting.FileSystemObject")
dim objFile:Set objFile = objFSO.GetFile(zFile)
GetSize = ConvertSize(objFile.Size)
End Function
'_____________________________________________________________________________________________________________________________
Function ConvertSize(Size)
Do While InStr(Size,",") 'Remove commas from size
CommaLocate = InStr(Size,",")
Size = Mid(Size,1,CommaLocate - 1) & _
Mid(Size,CommaLocate + 1,Len(Size) - CommaLocate)
Loop
Dim Suffix:Suffix = " Bytes"
If Size >= 1024 Then suffix = " KB"
If Size >= 1048576 Then suffix = " MB"
If Size >= 1073741824 Then suffix = " GB"
If Size >= 1099511627776 Then suffix = " TB"
Select Case Suffix
Case " KB" Size = Round(Size / 1024, 1)
Case " MB" Size = Round(Size / 1048576, 1)
Case " GB" Size = Round(Size / 1073741824, 1)
Case " TB" Size = Round(Size / 1099511627776, 1)
End Select
ConvertSize = Size & Suffix
End Function
'_____________________________________________________________________________________________________________________________
Function IsAPST(p_PSTGuid)
Dim x, P_PSTGuildValue
Dim P_PSTCheck:P_PSTCheck=0
IsAPST=False
oReg.GetBinaryValue HKEY_CURRENT_USER,p_PSTGuid,r_PSTCheckFile,P_PSTGuildValue
If IsUsableArray (P_PSTGuildValue) Then
For Each x in (P_PSTGuildValue)
P_PSTCheck = P_PSTCheck + Hex(x)
Next
End If
If P_PSTCheck=20 Then IsAPST=True
End Function
'_____________________________________________________________________________________________________________________________
Function PSTlocation(p_PSTGuid)
Dim y, P_PSTGuildValue
oReg.GetBinaryValue HKEY_CURRENT_USER,p_PSTGuid,r_PSTGuidLocation,P_PSTGuildValue
If IsUsableArray (P_PSTGuildValue) Then
For Each y In P_PSTGuildValue
If Len(Hex(y)) = 1 Then
PSTlocation = PSTlocation & CInt("0") & Hex(y)
Else
PSTlocation = PSTlocation & Hex(y)
End If
Next
End If
End Function
'_____________________________________________________________________________________________________________________________
Function PSTFileName(p_PSTGuid)
Dim z, P_PSTName
Dim strString : strString = ""
oReg.GetBinaryValue HKEY_CURRENT_USER,p_PSTGuid,r_PSTFile,P_PSTName
If IsUsableArray (P_PSTName) Then
For Each z in P_PSTName
If z > 0 Then strString = strString & Chr(z)
Next
End If
PSTFileName = strString
End Function
'_________________________________________________________________________________________________________
Function ExpandEvnVariable(ExpandThis)
Dim objWSHShell:Set objWSHShell = CreateObject("WScript.Shell")
ExpandEvnVariable = objWSHShell.ExpandEnvironmentStrings("%" & ExpandThis & "%")
End Function
'_________________________________________________________________________________________________________
Function IsUsableArray(rvnt)'-- Use this function to test for a Null, Empty or an undimensioned array.'-- Useful b/c some interfaces can hold properties for which if they have a'-- value will be an Array but may also be Null or an undimensioned Array.
'-- It assumes that a Null or Empty could potentially be an array but not yet dimensioned. '-- It returns -1 if it is passed a string, long, etc...'-- It returns 0 for an empty array or the number of elements in the first dimension.
IsUsableArray = 0
If (VarType(rvnt) And 8192) = 8192 Then
IsUsableArray = UBound(rvnt) - LBound(rvnt) + 1
Else
If Not (IsEmpty(rvnt) Or IsNull(rvnt)) Then IsUsableArray = -1
End If
End Function

The script works on my system if i correct the extra space at line 8 (Windows Messaging Subsystem)
It is a big script for what it offers, see here for a smaller one which offers more using the free to download library Redemption at http://www.dimastr.com/redemption/home.htm which is what CDO should have been.
set Session = CreateObject("Redemption.RDOSession")
const skUnknown = 0, olStoreANSI = 1, olStoreUnicode = 2, skPrimaryExchangeMailbox = 3, skPublicFolders = 5, skDelegateExchangeMailbox = 4
Session.Logon
for each Store in Session.Stores
if (Store.StoreKind = olStoreANSI) then
wscript.echo Store.Name & " - " & Store.PstPath & " " & Store.Name
elseif (Store.StoreKind = olStoreUnicode) Then
wscript.echo Store.Name & " - " & Store.PstPath
ElseIf (Store.StoreKind = skPrimaryExchangeMailbox) or (Store.StoreKind = skDelegateExchangeMailbox) or (Store.StoreKind = skPublicFolders) Then
wscript.echo Store.Name & " - " & Store.ServerDN
Else
wscript.echo Store.Name & " - " & Store.StoreKind
End If
next

Related

Vbscript how to find the first char from the end in text

I have problem with find the first char from the end in text.
For example, find space(" ") or new line(vbCrLf) on "Father go home" i get the index of first space from the end and on "Father go home/ntomorrow" i get the index of /n.
my code:
Function checkTextFunction( i_valueCheck)
Dim whereSpace
Dim WhereNewLine
Dim indexOFirstSpaceFromTheEnd
If Right(i_valueCheck,1) = " " Or Right(i_valueCheck,1) = vbCrLf Then
indexOFirstSpaceFromTheEnd = -1
Else
whereSpace = InStrRev(i_valueCheck, " ", -1,0)
WhereNewLine = InStrRev(i_valueCheck, vbCrLf, -1,0)
If whereSpace < WhereNewLine Then
indexOFirstSpaceFromTheEnd = whereSpace
Else
indexOFirstSpaceFromTheEnd = WhereNewLine
End If
End IF
WriteLogFileLine "indexOFirstSpaceFromTheEnd: " & indexOFirstSpaceFromTheEnd & " Right(i_valueCheck,1): " & Right(i_valueCheck,1) & vbCrLf & vbCrLf
checkTextFunction = indexOFirstSpaceFromTheEnd
End Function
but i don't find the first occurrence with the lines
whereSpace = InStrRev(i_valueCheck, " ", 1)
WhereNewLine = InStrRev(i_valueCheck, vbCrLf,1)
i get always 0.
Someone have idea?
******* I edit my question !!!!.
Thanks,
Tal
vbCrLf is actually 2 characters, so you want to specify Right(i_valueCheck, 2) = vbCrLf
If the character is not in the string, then InStrRev will return 0.. which would mean it is always the first occurrence. The second If statement should be a little more explicit in terms of the values of the variables.
Since you're not initializing indexOFirstSpaceFromTheEnd... If there are no vbCrLf or " " characters- it will remain empty. Therefore you should add a check in order to return a value every time... regardless of the string. I picked one million arbitrarily.
Function checkTextFunction(ByRef i_valueCheck)
Dim whereSpace
Dim whereNewLine
Dim indexOFirstSpaceFromTheEnd
If Right(i_valueCheck,1) = " " Or Right(i_valueCheck,2) = vbCrLf Then
indexOFirstSpaceFromTheEnd = -1
Else
whereSpace = InStrRev(i_valueCheck, " ", -1, 0)
whereNewLine = InStrRev(i_valueCheck, vbCrLf, -1, 0)
If whereSpace > 0 And (whereSpace < whereNewLine Or whereNewLine = 0) Then
indexOFirstSpaceFromTheEnd = whereSpace
ElseIf whereNewLine > 0 And (whereNewLine < whereSpace Or whereSpace = 0) Then
indexOFirstSpaceFromTheEnd = whereNewLine
End If
End If
If indexOFirstSpaceFromTheEnd = vbEmpty Then indexOFirstSpaceFromTheEnd = 1000000
WriteLogFileLine "indexOFirstSpaceFromTheEnd: " & _
indexOFirstSpaceFromTheEnd & _
" Right(i_valueCheck,1): " & _
Right(i_valueCheck,1) & vbCrLf & vbCrLf
checkTextFunction = indexOFirstSpaceFromTheEnd
End Function
This should help you get started... realistically- if you want to find the first occurrence of vbCrLf or " " then you're going to have to operate a While loop in order to keep checking (with InStrRev) that the index is actually the last occurrence.
For example: with the code above... look at the output of checkTextFunction(Space(2) & "test")
The final answer: if the last char in "i_valueCheck" is not space or vbCrLf it's find the first case(space or vbCrLf) from the end of "i_valueCheck".
Function checkTextFunction( i_valueCheck)
Dim whereSpace
Dim whereNewLine
Dim indexOFirstSpaceFromTheEnd
If Right(i_valueCheck,1) = " " Or Right(i_valueCheck,2) = vbCrLf Then
indexOFirstSpaceFromTheEnd = -1
Else
whereSpace = InStrRev(i_valueCheck, " ", -1, 0)
whereNewLine = InStrRev(i_valueCheck, vbCrLf, -1, 0)
If whereSpace > 0 And (whereSpace > whereNewLine Or whereNewLine = 0) Then
indexOFirstSpaceFromTheEnd = whereSpace
ElseIf whereNewLine > 0 And (whereNewLine > whereSpace Or whereSpace = 0) Then
indexOFirstSpaceFromTheEnd = whereNewLine
Else
indexOFirstSpaceFromTheEnd = -1
End If
End If
checkTextFunction = indexOFirstSpaceFromTheEnd End Function

Adding Base 36 to Base 10 conversion

I am trying to build on this previous post that works to convert a number to the specified base.
In my case I have a vbs script that is looking up a serial number and is outputting the alphanumeric character (base 36) to a txt file.
I would like to add to the txt file the base 10 value of the serial number. So I get an output like this:
Serial Number: ABC1234
Service Code: 22453156048
This is my starting point. This script runs and gives me a txt file with the Serial Number.
On Error Resume Next
' Initialize WSH objects
Set FSO = CreateObject("Scripting.FileSystemObject")
Set Shell = WScript.CreateObject("WScript.Shell")
Set WNetwork = WScript.CreateObject("WScript.Network")
' Initialize WMI
Set WMI = GetObject("winmgmts:\\.\root\cimv2")
' Find client machine name
Set ComputerInfo = WMI.ExecQuery("Select * from Win32_ComputerSystem")
For Each temp In Computerinfo
WorkstationName = WNetwork.ComputerName
Next
Set Bios = WMI.ExecQuery("Select * from Win32_BIOS")
For Each temp In Bios
SerN = temp.SerialNumber
Next
' Create Logfiles
Dim sDateTimeStamp
sDateTimeStamp = cStr(Year(now())) & _
Pad(cStr(Month(now())),2) & _
Pad(cStr(Day(now())),2) & _
Pad(cStr(Hour(now())),2) & _
Pad(cStr(Minute(now())),2) & _
Pad(cStr(Second(now())),2)
Function Pad(CStr2Pad, ReqStrLen)
Dim Num2Pad
Pad = CStr2Pad
If Len(CStr2Pad) < ReqStrLen Then
Num2Pad = String((ReqStrlen - Len(CStr2Pad)), "0")
Pad = Num2Pad & CStr2Pad
End If
End Function
Set LogFile = FSO.CreateTextFile("c:\logs\" & WorkstationName & "_" & sDateTimeStamp & ".txt")
Set EnviromentVariables = Shell.Environment("PROCESS")
LogFile.Writeline("Serial Number:" & space(2) & SerN)
But when I try to add the script from the linked post I do not get any output file.
On Error Resume Next
' Initialize WSH objects
Set FSO = CreateObject("Scripting.FileSystemObject")
Set Shell = WScript.CreateObject("WScript.Shell")
Set WNetwork = WScript.CreateObject("WScript.Network")
' Initialize WMI
Set WMI = GetObject("winmgmts:\\.\root\cimv2")
' Find client machine name
Set ComputerInfo = WMI.ExecQuery("Select * from Win32_ComputerSystem")
For Each temp In Computerinfo
WorkstationName = WNetwork.ComputerName
Next
Set Bios = WMI.ExecQuery("Select * from Win32_BIOS")
For Each temp In Bios
SerN = temp.SerialNumber
Function ToBase(ByVal n, b)
b = 10
n = SerN
If b < 2 Or b > 36 Then Exit Function
Const SYMBOLS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Do
ToBase = Mid(SYMBOLS, n Mod b + 1, 1) & ToBase
n = Int(n / b)
Loop While n > 0
End Function
SrvCode = ToBase(SerN,10)
Next
' Create Logfiles
Dim sDateTimeStamp
sDateTimeStamp = cStr(Year(now())) & _
Pad(cStr(Month(now())),2) & _
Pad(cStr(Day(now())),2) & _
Pad(cStr(Hour(now())),2) & _
Pad(cStr(Minute(now())),2) & _
Pad(cStr(Second(now())),2)
Function Pad(CStr2Pad, ReqStrLen)
Dim Num2Pad
Pad = CStr2Pad
If Len(CStr2Pad) < ReqStrLen Then
Num2Pad = String((ReqStrlen - Len(CStr2Pad)), "0")
Pad = Num2Pad & CStr2Pad
End If
End Function
Set LogFile = FSO.CreateTextFile("c:\logs\" & WorkstationName & "_" & sDateTimeStamp & ".txt")
Set EnviromentVariables = Shell.Environment("PROCESS")
LogFile.Writeline("Serial Number:" & space(2) & SerN)
LogFile.Writeline("Service Code:" & space(3) & SrvCode)
Nested function definitions aren't allowed in VBScript. This should be raising a syntax error, despite the global On Error Resume Next (which you shouldn't be using in the first place).
Put the function definition somewhere in the global scope (outside the loop), e.g. by changing this:
Set Bios = WMI.ExecQuery("Select * from Win32_BIOS")
For Each temp In Bios
SerN = temp.SerialNumber
Function ToBase(ByVal n, b)
b = 10
n = SerN
If b < 2 Or b > 36 Then Exit Function
Const SYMBOLS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Do
ToBase = Mid(SYMBOLS, n Mod b + 1, 1) & ToBase
n = Int(n / b)
Loop While n > 0
End Function
SrvCode = ToBase(SerN,10)
Next
into this:
Function ToBase(ByVal n, b)
If b < 2 Or b > 36 Then Exit Function
Const SYMBOLS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Do
ToBase = Mid(SYMBOLS, n Mod b + 1, 1) & ToBase
n = Int(n / b)
Loop While n > 0
End Function
Set Bios = WMI.ExecQuery("Select * from Win32_BIOS")
For Each temp In Bios
SerN = temp.SerialNumber
SrvCode = ToBase(SerN,10)
Next
Make sure to remove the lines b = 10 and n = SerN. They're messing up the values passed to the parameters b and n.
Credit >> https://web.archive.org/web/20190717135154/http://www.4guysfromrolla.com:80/webtech/032400-1.shtml
I was unable to get the calculation to run using the ToBase Function. But with some more googling I found the above link and I was able to use the referenced function to get the desired output. This now allows me add to a existing script to get the express service code when doing a remote lookup of a Dell computers Service Tag.
So here is the final working script that gives the expected output.
' Initialize WSH objects
Set FSO = CreateObject("Scripting.FileSystemObject")
Set Shell = WScript.CreateObject("WScript.Shell")
Set WNetwork = WScript.CreateObject("WScript.Network")
' Initialize WMI
Set WMI = GetObject("winmgmts:\\.\root\cimv2")
' Find client machine name
Set ComputerInfo = WMI.ExecQuery("Select * from Win32_ComputerSystem")
For Each temp In Computerinfo
WorkstationName = WNetwork.ComputerName
Next
Function baseN2dec(value, inBase)
'Converts any base to base 10
Dim strValue, i, x, y
strValue = StrReverse(CStr(UCase(value)))
For i = 0 To Len(strValue)-1
x = Mid(strValue, i+1, 1)
If Not isNumeric(x) Then
y = y + ((Asc(x) - 65) + 10) * (inBase ^ i)
Else
y = y + ((inBase ^ i) * CInt(x))
End If
Next
baseN2dec = y
End Function
Set Bios = WMI.ExecQuery("Select * from Win32_BIOS")
For Each temp In Bios
SerN = temp.SerialNumber
SrvCd = baseN2dec(SerN, 36)
Next
' Create Logfiles
Dim sDateTimeStamp
sDateTimeStamp = cStr(Year(now())) & _
Pad(cStr(Month(now())),2) & _
Pad(cStr(Day(now())),2) & _
Pad(cStr(Hour(now())),2) & _
Pad(cStr(Minute(now())),2) & _
Pad(cStr(Second(now())),2)
Function Pad(CStr2Pad, ReqStrLen)
Dim Num2Pad
Pad = CStr2Pad
If Len(CStr2Pad) < ReqStrLen Then
Num2Pad = String((ReqStrlen - Len(CStr2Pad)), "0")
Pad = Num2Pad & CStr2Pad
End If
End Function
Set LogFile = FSO.CreateTextFile("c:\logs\" & WorkstationName & "_" & sDateTimeStamp & ".txt")
Set EnviromentVariables = Shell.Environment("PROCESS")
LogFile.Writeline("Serial Number:" & space(2) & SerN)
LogFile.Writeline("Service Code:" & space(3) & SrvCd)

Webcam application to save image to database

I want to create a webcam application that can save image to database. My code is from the internet. My code can only save binary but I guess my conversion was incorrect because I can't retrieve them from the database.
Here is my Code:
Private Sub cmdsave_Click()
OpenDB
rs.Open "tblimg", db, adOpenKeyset, adLockPessimistic, adCmdTable
Dim bytData() As Byte, PicInfo As BITMAP
If Dir(App.path & "\myPic", vbDirectory) = "" Then MkDir (App.path & "\myPic")
File1.path = App.path & "\myPic"
'File1.Pattern = "*.bmp"
File1.Pattern = "*.jpg"
File1.Refresh
Dim Maxnum As Integer, ii As Integer
For ii = 0 To File1.ListCount - 1
If Left(File1.List(ii), 1) = "p" Then
If CInt(Mid(File1.List(ii), 2, Len(File1.List(ii)) - 4)) > Maxnum Then
Maxnum = CInt(Mid(File1.List(ii), 2, Len(File1.List(ii)) - 4))
End If
End If
Next
Picture1.Picture = Image1.Picture
'SavePicture Image1.Picture, App.Path & "\myPic\p" & Maxnum + 1 & ".bmp"
SAVEJPEG App.path & "\myPic\p" & Maxnum + 1 & ".jpg", 100, Me.Picture1
ReDim bytData((PicInfo.bmHeight * PicInfo.bmWidth)) As Byte
With rs
.AddNew
.Fields("Picture").AppendChunk bytData
.Fields("Desc") = Label2.Caption
.Update
End With
Set rs = Nothing
db.Close: Set db = Nothing
End Sub
Hope this code give you idea of what you want to achive
Picture3.Visible = True
SavePicture Picture1.Picture, App.Path & "\Emp Photo\" & UCase(Trim(G_EmpCode)) _ & ".jpg"
Picture3.Picture = LoadPicture(App.Path & "\Emp Photo\" & UCase(Trim(G_EmpCode)) & ".jpg")
Picture2.Picture = LoadPicture(App.Path & "\Emp Photo\" & UCase(Trim(G_EmpCode)) & ".jpg")
FrmEmployee.Image1.Picture = Picture2.Picture
CCTVImagePath = App.Path & "\Emp Photo\" & UCase(Trim(G_EmpCode)) & ".jpg"
Call cmdClose_Click
Call CmdStart_Click
If CCTVImagePath <> "" Then
ImagePath = CCTVImagePath
m_imgfile = CCTVImagePath
End If
If FileSystemObj.FileExists(ImagePath) = True Then
Set strStream = New ADODB.Stream
strStream.Type = adTypeBinary
strStream.Open
Sourcefile = ImagePath
strStream.LoadFromFile Sourcefile
CCTVImagePath = ""
End If
CCTVImagePath = ""

VB Script that will manipulate a file name

Ok, like many other people, I am a noob on VB Scripting. What I am trying to do is create a VB Script that will manipulate a file name from Fulton A1032-CCC Adamsville to just A1032-CCC. I have browsed many site trying to find the answer but only came up with on that halfway worked.
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colFiles = objWMIService.ExecQuery _
("ASSOCIATORS OF {Win32_Directory.Name='H:\Darrell 2014 folder\Distview Wiki Revamp\To'} Where " _
& "ResultClass = CIM_DataFile")
For Each objFile In colFiles
strPath = objFile.Drive & objFile.Path
strExtension = objFile.Extension
strFileName = objFile.FileName
If Left(strFileName, 7) = "Fulton " Then
intLength = Len(strFileName)
strFileName = Right(strFileName, intLength - 7)
End If
If Right(strFileName, 10) = " Adamsville" Then
intLength = Len(strFileName)
strFileName = Left(strFileName, intLength - 10)
End If
strNewName = strPath & strFileName & "." & strExtension
errResult = objFile.Rename(strNewName)
Next
Please Help
Why not just use the replace function instead? For example:
Dim fileName As String
fileName = "Fulton A1032-CCC Adamsville"
fileName = Replace(fileName, "Fulton ", "")
fileName = Replace(fileName, " Adamsville", "")
MsgBox fileName
The output is A1032-CCC. This also works if either or both of the search strings don't exist.
Learn to count:
>> WScript.Echo Len(" Adamsville")
>>
11
>>
or write a function:
>> Function endsWith(b, t)
>> endsWith = Right(b, len(t)) = t
>> End Function
>> WScript.Echo CStr(endsWith("Fulton A1032-CCC Adamsville", " Adamsville"))
>>
True
Update wrt downvotes:
As the downvotes indicate that there are at least two people who can't count either:
Option Explicit
Function qq(s) : qq = """" & s & """" : End Function
Dim strFileName : strFileName = "Fulton A1032-CCC Adamsville"
Dim intLength
WScript.Echo 0, qq(strFileName)
' assume the structure of the input data is:
' <todelete+blank><tokeep><blank+todelete>
WScript.Echo 1, qq(Split(strFileName)(1))
' the ot's code 'works' if you count correctly
If Left(strFileName, 7) = "Fulton " Then
intLength = Len(strFileName)
strFileName = Right(strFileName, intLength - 7)
End If
If Right(strFileName, 11) = " Adamsville" Then
intLength = Len(strFileName)
strFileName = Left(strFileName, intLength - 11)
End If
WScript.Echo 2, qq(strFileName)
output:
cscript 25689666.vbs
0 "Fulton A1032-CCC Adamsville"
1 "A1032-CCC"
2 "A1032-CCC"

Excel VB to QTP 11 script convertion issue

I have written script in Excel VBA and it is working fine, now I am trying to covert the same to QTP 11.0 - however facing some issue.
Updated Question based on suggestion by Xiaofu -
What is the VBA - shell function equivalent in QTP 11?
And below is QTP 11 Script:
Extern.Declare micHwnd, "OpenProcess", "kernel32", "OpenProcess", micLong, micLong, micLong
Extern.Declare micHwnd, "WaitForSingleObject", "kernel32", "WaitForSingleObject", micLong, micLong
Extern.Declare micHwnd, "CloseHandle", "kernel32", "CloseHandle", micLong
Const PROCESS_QUERY_INFORMATION = &H400
Const SYNCHRONIZE = &H100000
Const SWP_NOMOVE = 2
Const SWP_NOSIZE = 1
Const HWND_TOPMOST = -1
Const HWND_NOTOPMOST = -2
Const STATUS_PENDING = &H103
Const STILL_ACTIVE = &H103
Const WAIT_TIMEOUT = &H102
Const INFINITE = &HFFFFFFFF
Public Function test_exe()
Dim argStr
argStr = "cmd.exe /c " + Chr(34) & "plink.exe -load " + Chr(34) + session_name + Chr(34) + " -l " + Chr(34) + login_id + Chr(34) + " -pw " + Chr(34) + dns_pwd + Chr(34) + " -m " + Chr(34) + cmd_dir + "commands.txt" + Chr(34) + " >> " + Chr(34) + log_dir & log_filename + Chr(34) + Chr(34)
exeCount = Run_Test(argStr, log_dir + log_filename)
End Function
Public Function Run_Test(exeStr, ByVal logFile)
Dim pid, ExitEvent
Dim lineStr
Dim okFlg
Dim hProcess
exeCount = "0"
okFlg = 0
pid = shell(exeStr, vbHide)
hProcess = Extern.OpenProcess(PROCESS_QUERY_INFORMATION + SYNCHRONIZE, 0, pid)
ExitEvent = Extern.WaitForSingleObject(hProcess, 15000)
Extern.CloseHandle(hProcess)
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile(logFile, ForWriting, True)
Do
f.writeLine lineStr
If InStr(1, lineStr, "/home/") > 0 Then okFlg = okFlg + 1
exeCount = "1"
Loop Until EOF(3)
f.close
If okFlg >= 1 Then
Run_Test = okFlg
Else
Run_Test = -1
End If
End Function
Error that I am getting is on line "**pid = shell(exeStr, vbHide)**" - "Object doesn't support this property or method: 'shell'"
Any suggestion on how to resolve this issue?
I would suggest you make use of the DotNetFactory to access all that .NET goodness:
Dim csProcess
Set csProcess = DotNetFactory.CreateInstance("System.Diagnostics.Process")
Dim myProcess
Set myProcess = csProcess.Start("notepad.exe")
MsgBox myProcess.Id
If you are not familiar with or don't have access to the MSDN documentation, here is an example with command-line arguments:
Dim SystemProcess
Set SystemProcess = DotNetFactory.CreateInstance("System.Diagnostics.Process")
Dim processStartInfo
Set processStartInfo = DotNetFactory.CreateInstance("System.Diagnostics.ProcessStartInfo")
processStartInfo.FileName = "cmd.exe"
processStartInfo.Arguments = "/c notepad.exe"
Dim myProcess
Set myProcess = SystemProcess.Start(processStartInfo)
msgbox myProcess.Id

Resources