The following code is a peace of a script that is set up to be executed by InstallShield when installing my application: Custom Actions During Installation > After Register Product
Set wsShell = CreateObject("WScript.Shell")
wsShell.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\My Program\FilePath", "{the file path}"
When I run the script from command line it runs as it should and writes to the registry. But when I try to use the setup file it shows no errors, but the registry value is not set.
Why is it not working?
I'm running it as administrator.
You can use this code to log information in you msi log, it might help you figure out what is happening
Function LogMSIInfo(msg,msgtype)
Dim rec
Set rec = Session.Installer.CreateRecord(1)
rec.StringData(0) = msg
LogMSIInfo = Session.Message(&H04000000, rec)
End Function
Related
I used to run 3 SAS EG Projects on a daily basis. Since a couple of days, we have a "SAS Scheduler" that is basically running those latter during the night (the first one at 00:00 AM, second one at 01:00 AM, third one at 03:00 AM). Each SAS Project has multiple SAS Programs.
All in all, that is great news, but this also mean I can't check the logs directly anymore.
To keep track of the night jobs, I am trying to find what could be the best way to export the log files for each project. I found out about the SAS Project Log recently, which basically summarize the logs from all the programs within a SAS Project.
I discovered CaseySmith's answer on the SAS Community forum, basically tweaking the .vbs script to save the SAS Project log file to a .txt using the following code:
Set objProjectLog = objProject.ProjectLog
objProjectLog.Clear()
objProjectLog.Enabled = True
'strProjectLog = objProjectLog.Text
objProjectLog.SaveAs "c:\temp\projectLog.txt"
But, 1) It is a .txt file not a log file and 2) I don't know where to add it in my current .vbs script:
Option Explicit
Dim app
Call dowork
'shut down the app
If not (app Is Nothing) Then
app.Quit
Set app = Nothing
End If
Sub dowork()
On Error Resume Next
'----
' Start up Enterprise Guide using the project name
'----
Dim prjName
Dim prjObject
prjName = "C:\Users\kermit\Desktop\Project.egp" 'Project Name
Set app = CreateObject("SASEGObjectModel.Application.8.1")
If Checkerror("CreateObject") = True Then
Exit Sub
End If
'-----
' open the project
'-----
Set prjObject = app.Open(prjName,"")
If Checkerror("app.Open") = True Then
Exit Sub
End If
'-----
' run the project
'-----
prjObject.run
If Checkerror("Project.run") = True Then
Exit Sub
End If
'-----
' Save the new project
'-----
prjObject.Save
If Checkerror("Project.Save") = True Then
Exit Sub
End If
'-----
' Close the project
'-----
prjObject.Close
If Checkerror("Project.Close") = True Then
Exit Sub
End If
End Sub
Function Checkerror(fnName)
Checkerror = False
Dim strmsg
Dim errNum
If Err.Number <> 0 Then
strmsg = "Error #" & Hex(Err.Number) & vbCrLf & "In Function " & fnName & vbCrLf & Err.Description
'MsgBox strmsg 'Uncomment this line if you want to be notified via MessageBox of Errors in the script.
Checkerror = True
End If
End Function
In the end, what I would like is that on the morning, I run a program that scan the 3 project log files for Notes, Warning and Errors and send to myself an email with the results. Hence, is there a way to export the SAS Project Log (not manually) in a folder?
So, first, what is this code doing?
Set objProjectLog = objProject.ProjectLog
objProjectLog.Clear()
This clears the project log. This needs to be done before your project is run - otherwise the log contains data from past runs. So put this before the prjOBject.Run().
objProjectLog.Enabled = True
'strProjectLog = objProjectLog.Text
objProjectLog.SaveAs "c:\temp\projectLog.txt"
This then exports the project log to a text file. You of course can call that text file whatever you want. You need this code to appear after your program runs, and somewhere before it closes. Right after PrjObject.Run() is probably fine.
You will need to update the names to match your vbs file's names - they use objproject and your vbs uses prjObject, but those are the same thing, just match the names.
Second - what else could you do? If VBS isn't your thing, you have a lot of other ways you could do this.
Export your EG project to a .sas file, then schedule this in base SAS with the normal output options. This may also be possible via the scheduling interface.
Use PROC PRINTTO to redirect your log inside your SAS code.
Copy your EG project to a location you can see. The EG project does contain the log of everything that was run - so there's no reason you couldn't just open the .egp and look at it, just make sure you're not doing that with the production file since you might forget to close out.
My preference is not to schedule EG projects, but to schedule .sas programs; use EG as the development environment and then export to .sas. This gives you more flexibility. But there are a lot of different ways to skin this cat.
I'm trying to set up automated emailing of a few reports for my company and have a few questions after doing some research into it.
So far I have the emailing portion finished and working of MS-Access where it will send emails containing two reports to whomever. I have also set up a .bat file to run the macro automatically and can use task scheduler in order to run the macro while I'm logged in and receive the emails.
The problem is I'm trying to set it up so that it will run overnight bi-weekly. When I test out the task scheduler with the option "Run whether logged on or not"(which since my account does not have admin privileges, I had to switch into an admin account and give my account log on as batch job rights) and try to run it while being logged out, unfortunately it doesn't work.
I have tried out running both Access directly through the task scheduler as well as through a .bat file. The results from the .bat file show that the operation completed successfully, but no emails will go through and as far as I know, the .bat program does not properly execute. When I attempt to run access directly through the task scheduler, the error shows that the operator or administrator has refused the request(0x800710E0).
Would I need to be running my account as a local administrator in order for this to work? Or should I try to write a batch file with AT commands to try to schedule this?
This is my first attempt at doing anything with Windows for automated scheduling as I've only ever used the crontab functions within linux. Any advice or help would be greatly appreciated, as well as any questions that might help my clarify what I'm trying to do here.
Code for the .bat file:
start "C:\Program Files (x86)\Microsoft Office\root\Office16\MSACCESS.EXE" "C:\Users\*User*\Documents\Asset List Backup 20191126.accdb" /x SendEmail
Edit:
Code for the Email:
Public Function Sendemail1()
Dim crrntdate As String
Dim ol As Outlook.Application, msg As MailItem, atts As Attachments, strFilePath As String, strFilePath2 As String
Set ol = CreateObject("Outlook.Application")
crrntdate = Format(DateValue(Now), "mmddyyyy")
strFilePath = "C:\Users\USER\Documents\Auto Reports\Office Consumables Report " & crrntdate & ".pdf"
strFilePath2 = "C:\Users\USER\Documents\Auto Reports\Field Consumables Report " & crrntdate & ".pdf"
DoCmd.OutputTo acOutputReport, "AutoCountReport", acFormatPDF, strFilePath, False
DoCmd.OutputTo acOutputReport, "AutoCountFieldReport", acFormatPDF, strFilePath2, False
DoEvents
Set msg = ol.CreateItem(olMailItem)
Set atts = msg.Attachments
With msg
.Subject = "Automatic Report for Office Consumables " & crrntdate
.Body = "Body text" 'Edited
.To = "Email" 'Edited
.CC = ""
atts.Add strFilePath
atts.Add strFilePath2
.Send
End With
End Function
I am trying to run a VBScript but CFExecute throws an error
<cfexecute name = "C:\Windows\System32\CScript.exe"
arguments = "//NoLogo D:\Excel.vbs D:\test.xls"
variable = "data"
timeout = "100">
</cfexecute>
<cfdump var="#data#">
Error:
Error: 424 Source: Microsoft VBScript runtime error Description: Object required
But when I run the VBScript with CMD it works fine
C:\Windows\System32 > cscript //nologo D:\Excel.vbs D:\test.xls
I have full admin access, so why am I getting this error?
It was due to bug in the Windows 2008 server.
For office automation (accessing via script and non-window based operation) we have to add a "Desktop" folder inside
C:\Windows\System32\config\systemprofile
C:\Windows\SysWOW64\config\system32
I added it and found success.
Create a vbscirpt file (.vbs). The code content would have the task you want to achieve.
The below example contains the vbscript file, that refreshes the excel and the cfm which executes the vbscript.
Sample vbscript file code:-
Set fso = CreateObject("Scripting.FileSystemObject")
Set xl = CreateObject("Excel.Application")
xl.Visible = True
For Each f In fso.GetFolder("C:\inetpub\WebSites\Upload\").Files
If LCase(fso.GetExtensionName(f.Name)) = "xlsx" Then
Set wb = xl.Workbooks.Open(f.Path)
wb.RefreshAll
wb.Save
wb.Close
End If
Next
xl.Quit
Sample cfm file code:-
<cfexecute name = "C:\Windows\System32\cscript.exe" arguments = "C:\inetpub\WebSites\CSAT\test.vbs">
</cfexecute>
I have the following vbs script from Microsoft Support for adding Excel add-in:
Dim oXL As Object
Dim oAddin As Object
Set oXL = CreateObject("Excel.Application")
oXL.Workbooks.Add
Set oAddin = oXL.AddIns.Add("c:\Program Files\MyApp\MyAddin.xla", True)
oAddin.Installed = True
oXL.Quit
Set oXL = Nothing
I save the above script to a file called as addin.vbs and run it from a command console:
C:\...>cscript addin.vbs
I got the following error:
c:\...\addin.vbs(1, 9) Microsoft VBScript compilation error: Expected end of statement
Not sure how I can run it from cmd console?
I am running it from Windows XP.
Visual Basic for Applications (VBA, which your code is written in) and Visual Basic Scripting Edition (VBS) are not the same language.
Windows Scripting Host (WSH, i.e. cscript.exe and wscript.exe) only handles Active Scripting languages (in most installs, VBScript and JScript). VBA can only be run within the application that is destined to host it.
Just follow the directions on the Microsoft Support page you have and add the script to Excel.
The error occurs because of the As Object clause. Unlike VBA, VBScript has only one data type — Variant, so you don't specify the data type when declaring a variable. Remove the As Object clauses and the script should work fine:
Dim oXL, oAddin
Set oXL = CreateObject("Excel.Application")
oXL.Workbooks.Add
Set oAddin = oXL.AddIns.Add("c:\Program Files\MyApp\MyAddin.xla", True)
oAddin.Installed = True
oXL.Quit
Set oXL = Nothing
I'm trying to do a script that gets information out of some MSI and MST files and write it into a text file. I achieved reading the MSI files. However, I get the following message.
Msi API Error 80004005: OpenDatabase, DatabasePath, OpenMode
1:2219 2: 3:4:
I open the file like this
Set installer = Wscript.CreateObject("WindowsInstaller.Installer") : CheckError
Dim database : Set database = installer.OpenDatabase(FileName, msiOpenDatabaseModeReadOnly) : CheckError
It works just fine with MSI files. I believe MST files should be read in a different way.
How can a read an MST file using vbscript?
I haven't tried myself, but according to MSDN, to view a transform file (MST) you need to open your MSI database and then use the ApplyTransform method with the msiTransformErrorViewTransform parameter. This will give you a temporary _TransformView table, which you can query to get the desired information.
So, your code should look like this:
Const msiOpenDatabaseModeReadOnly = 0
Const msiTransformErrorViewTransform = 256
Dim installer, database
Set installer = CreateObject("WindowsInstaller.Installer") : CheckError
Set database = installer.OpenDatabase(MSIFileName, msiOpenDatabaseModeReadOnly) : CheckError
database.ApplyTransform MSTFileName, msiTransformErrorViewTransform : CheckError