VBScript runtime error: ActiveX component can't create object: 'XStandard.MD5' - vbscript

The script work on the local computer but not remotely. Any idea?
I'm getting VBScript runtime error "ActiveX component can't create object: XStandard.MD5".
strSource = "C:\WINNT"
Set objFSO = CreateObject(Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(strSource)
Set colfiles = objFolder.Files
For each file in colfiles
Set objMD5 = CreateObject("XStandard.MD5")

Go to the DLL folder and use in command prompt > regsrv32 XMD35.dll
http://www.xstandard.com/en/documentation/xmd5/

When you want to instruct a remote computer to instantiate a given ActiveX object, you need to specify the name of the remote server when calling the CreateObject(progID, [serverName]) function.
Otherwise, the script engine attempts to instantiate the object from the local machine.
For example:
Set objMD5 = CreateObject("XStandard.MD5", nameOfYourServer)
And of course, the component must be available on the server.
More info about CreateObject at MSDN

I don't know if it has anything to do with the syntax of line 2. you are missing an open quotation. You have:
Set objFSO = CreateObject(Scripting.FileSystemObject")
You should have:
Set objFSO = CreateObject("Scripting.FileSystemObject")

I realize this is an old question, but google sent me here with the same problem. In my case it was a 32-bit vs 64-bit issue - I needed to use the 32-bit version of CScript to execute.
More details here http://blogs.msdn.com/b/helloworld/archive/2007/12/12/activex-component-can-t-create-object-when-creating-a-32-com-object-in-a-64-bit-machine.aspx

The XStandard.MD5 is a component that is NOT standard in all computers. it is something that needs to be installed. However even after installing you may still run into the same error. This may be because you are running the script in a 64bit system. for some reason the 64bit wscript won't use the xmd5.dll. however you can make a workaround by associating the scriptfiles to run on the 32bit version of wscript. by
going into your default programs. (Windows 8+ Right click the startbutton area [category view] Click Programs, then Default Programs then Associate a file type or protocol with a program) (Windows 7- click on start then click default programs)
Then click vbs then click change program, change it to
C:\Windows\SysWow64\Wscript.exe
NOTE ONLY ON 64BIT

As dmogle says in his comment, you need to make sure that the component is installed on the remote computer. Assuming that you've got access to that computer, download the dll to it and then run the command regsvr32 XMD5.dll as can be seen here.
On another note, your script looks a little funny, the twp last lines are:
For each file in colfiles
Set objMD5 = CreateObject("XStandard.MD5")
Which means that you'll be creating an instance of the MD5 object for each file. I've never used the component in question, but I'm fairly sure that you probably want to create only one instance of the object and then call the functions on that object multiple times. So I'd suggest changing the order of those lines to:
Set objMD5 = CreateObject("XStandard.MD5")
For each file in colfiles

Related

How to change Windows folder permission with VB.NET? (System.UnauthorizedAccessException)

I am working on this small VB.NET application which needs to copy a couple files to a Windows folder but I am getting an access denied error; then if I go to the folder, right-click it and manually write the write permission to the folder everything will work fine.
However this application is going to be used by our employees in several machines of the network and mostly of them has not this level of "expertise" meaning that the process must happen smoothly and automatically and therefore the change of the permission should be done by the application itself.
I found a code snippet online which supposed to fix the problem but it is not working for me. I am getting a runtime error with the following message:
System.UnauthorizedAccessException: 'Attempted to perform an unauthorized operation.'
And this is the code I am using:
Dim folder As String = "C:\Program Files (x86)\MyCompany\MyApp"
Dim sid As SecurityIdentifier = New SecurityIdentifier(WellKnownSidType.AuthenticatedUserSid, Nothing)
Dim writerule As FileSystemAccessRule = New FileSystemAccessRule(sid, FileSystemRights.Write, AccessControlType.Allow)
Dim fsecurity As DirectorySecurity = Directory.GetAccessControl(folder)
fsecurity.AddAccessRule(writerule)
Directory.SetAccessControl(folder, fsecurity) 'the error happens here
The error happen exactly in the line where the permission setting try to apply. Any idea?
The solution is to level up the privileges of the application. Here it is how to force the program to do it automatically without the need of right-click it and choose "run as administrator" every time:
https://mobitek-system.com/blog/2020/06/how-to-run-vb-net-code-as-an-administrator/
😁

VBScript to Open Powerpoint and Run Macro

I am trying to run a VBScript that opens powerpoint and runs a macro named UpdateandBreaklinks. The Script that I am running is as follows:
Dim oApp
Dim oPres
Dim oSlide
Set oApp = CreateObject("Powerpoint.Application")
oApp.visible = true
Set oPres = oApp.Presentations.Open("C:\Users\PPwithLinks.pptm")
Set oSlide = oPres.Slides(1).Duplicate
oApp.Run "PPwithLinks.pptm!UpdateandBreaklinks"
This Gets the script to Run and open Powerpoint, however the Macro is not Ran. I get an error on this line:
oApp.Run "PPwithLinks.pptm!UpdateandBreaklinks"
I have tried to adjust it to this:
oApp.Run "UpdateandBreaklinks"
But I still get the same error. The error reads as:
Application.Run: Invalid request. Sub or funtion not defined.
Code: 80048240
I have researched the problem and all I can find is that people have remedied this same issue with the code above. I am not sure what I am doing incorrectly.
I have further tested the problem and I am now at this point:
So, I created a new pptm, I created a new macro for MsgBox "Hello" within the pptm. When I call the pptm to be opened with VBS, the pptm opens and I still get the error.
BUT, testing further, if I have opened the pptm first and then call the VBS the macro does run.(It opens another instance of the program as a [Read-Only] and runs the macro.)
Also, if I just open the pptm from the VBS(delete the line that runs the macro) and then try to run the Macro manually within PowerPoint then I get the following error: "Because of your security settings, macros have been disabled."
I go into the Macro Security settings and they have not been changed, so it appears to me that when VBS Opens the pptm something is disabling the Macros and therefore erroring out the VBS code to not call and run the macro.

How Do I Prevent the Installer from Running when Application Data Files are Removed?

I have an application written in VB.Net with Visual Studio 2005. The application allows the user to create and save project files. When I distribute the application, I include some demo project files, which I install in the common application data folder.
XP - C:\Documents and Settings\All Users\Application Data
Vista & 7 - C:\Program Data
I have discovered an unexpected behavior -- if any file in the common application data folder is removed, and the application is run from the start menu, then the install procedure will start and attempt to restore the missing file(s). If the MSI file no longer exists at its original location or has been changed, then the application will fail to run. I perceive that this is a "feature", but it is one I don't want. Can anyone tell me what is going on and how I can avoid it?
Some more details:
I created the setup package by using a Visual Studio deployment
project.
This behavior will not occur if I launch the EXE directly. I
expect, therefore, that the behavior has something to do with the
start menu shortcut. I've noticed that the shortcut isn't a normal
shortcut -- it doesn't have a "Target Location".
All advice is appreciated.
-TC
I have learned that this behavior involves something called "Install-on-Demand" (aka "Self Heal"). The unusual shortcuts created by the setup package are called "Advertised Shortcuts". Now that I have a name for the problem, it is easy to find information on how to fix it. Notably:
http://msdn.microsoft.com/en-us/library/aa368297.aspx
http://groups.google.com/group/microsoft.public.dotnet.distributed_apps/browse_thread/thread/401847045f104af3
http://blog.jtbworld.com/2007/11/enable-target-and-change-icon-of.html
Those pages contain a wealth of information. For the convenience of others who may stumble upon this post, I will summarize what they say:
Advertised shortcuts are special shortcuts which do some fancy things. Most notably, they reinstall damaged application before launching their target. There is some debate over whether they are good, evil, or harmless. In my opinion, they do something most users don't expect, and that makes them evil. Therefore, I'd like to disable them for my application.
Visual Studio setup projects automatically create MSI packages which generate advertised shortcuts by default. It is easy to override that default when installing the MSI package by using DISABLEADVTSHORTCUTS=1 as a command-line argument for Setup.exe. Also, with a utility like Orca, you can manually change the default by inserting DISABLEADVTSHORTCUTS=1 as a property of the MSI. However, if you want Visual Studio to automatically create MSI packages which don't create advertised shortcuts, that is harder. I did it this way:
First, I created a VBS file using the DisableAdvt code provided by Gary Chang in one of the links above (I've repeated that code below). Just create a text file, paste in the code. and save it as DisableAdvt.vbs.
Then, create a post-build event for your setup project. The exact syntax will depend on your file locations. Because my DisableAdvt.vbs is in a "Tools" subfolder of the solution folder, my post-build event looks like this:
"$(ProjectDir)..\Tools\DisableAdvt\DisableAdvt.vbs" "$(BuiltOuputPath)"
That's all I had to do. It works like a charm.
-TC
Some notes:
In Visual Studio 2005, Build events are accessed differently for setup projects than they are for other types of projects. Click on the project name in the solution explorer, then look for PostBuildEvent in the Properties pane.
Orca is a utility that can be used to manually insert the DISABLEADVTSHORTCUTS property into the MSI file. With my approach, Orca is not necessary. However, it is useful for verifying that the build event is making the expected change.
http://www.technipages.com/download-orca-msi-editor.html
In the build event, the misspelling "BuiltOuputPath" is intentional.
Here is Gary Chang's DisableAdvt.vbs code (note that I fixed a typo on line 21 -- Very important!):
Option Explicit
Const msiOpenDatabaseModeTransact = 1
Dim argNum, argCount:argCount = Wscript.Arguments.Count
Dim openMode : openMode = msiOpenDatabaseModeTransact
' Connect to Windows installer object
On Error Resume Next
Dim installer : Set installer = Nothing
Set installer = Wscript.CreateObject("WindowsInstaller.Installer") :
CheckError
' Open database
Dim databasePath:databasePath = Wscript.Arguments(0)
Dim database : Set database = installer.OpenDatabase(databasePath, openMode) : CheckError
' Process SQL statements
Dim query, view, record, message, rowData, columnCount, delim, column
query = "INSERT INTO Property(Property, Value) VALUES ('DISABLEADVTSHORTCUTS', '1')"
Set view = database.OpenView(query) : CheckError
view.Execute : CheckError
database.Commit
If Not IsEmpty(message) Then Wscript.Echo message
Wscript.Quit 0
Sub CheckError
Dim message, errRec
If Err = 0 Then Exit Sub
message = Err.Source & " " & Hex(Err) & ": " & Err.Description
If Not installer Is Nothing Then
Set errRec = installer.LastErrorRecord
If Not errRec Is Nothing Then message = message & vbLf & errRec.FormatText
End If
Fail message
End Sub
Sub Fail(message)
Wscript.Echo message
Wscript.Quit 2
End Sub

Error: ActiveX Component Can't Create Object Scripting.FileSystemObject

I have a simple vbs-file on my drive c: with following content:
Set objShell = CreateObject("Scripting.FileSystemObject")
When I'm trying to launch it, I get error
c:\fso.vbs(1, 1) Microsoft VBScript
runtime error: ActiveX component can't
create object:
'Scripting.FileSystemObject'
I tried to login as admin and execute wscript -regserver, but didn't help.
Can someone help me please?
Assuming you are logged in as Admin, please have a look in registry for Scripting.FileSystemObject under HKCR.
If you can not find this PROGID then you are missing the required files or the component is disabled (not registered).
Scripting.FileSystemObject is implemented in scrrun.dll.
If re-registering scrrun.dll doesn't fix it, you might have to re-register a lot of other dependencies. The easiest way to do that is with MS Fixit 50123:
http://go.microsoft.com/?linkid=9666880
Run that, then try your FSO call again. This is the only thing that worked for me on a couple client computers that had various fake AV programs and reg cleaners.
In my case ProgId attribute on the COM component class was misspelled:
[ProgId("XXX")]

Registry key editing vb6 startup

Is it possible that someone here could explain how to use this code. Please keep in mind i am a complete amateur, so simplifications may be needed.
Private Const cPGM = "C:\VB Forum\startup\Example.exe"
Dim oShell As IWshShell_Class
Set oShell = New IWshShell_Class
oShell.RegWrite "HKLM\Software\Microsoft\Windows\CurrentVersion\Run\MyVBApp", _
cPGM, "REG_SZ"
How exactly is this code used? Is it saved as an .exe file and ran or what? Thanks for your prompt reply and informational feedback.
All this code does is add a value to the registry. It adds an item to the key
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
with the name MyVBApp, and the value C:\VB Forum\startup\Example.exe
As it states in the article, this registry entry will cause the program C:\VB Forum\startup\Example.exe to launch automatically at system startup.
In order to use this code it does somehow have to be executed which, of course, requires an executable. If you want to see this code in action, the simplest thing to do would be to create a new "Standard EXE" project, add a reference to the Windows Script Host Object Model, paste the code into the Form_Load event, then run the app. Look at this registry key and you'll see this new entry. Be sure and delete it though because I assume you don't have some executable named C:\VB Forum\startup\Example.exe that you wish to run every time Windows starts, do you?

Resources