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")]
Related
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/
😁
I am trying to install a VB6 application in Windows 10 computers, but when I load a child form and then unload it, the program crashes. If I start the application as Administrator from the shortcut, I can load and unload everything without issues. Have you experienced this before?
So far I've tried the following:
Started the .exe directly as Administrator. Not working.
Checked the Run As Administrator checkbox in the contextual menu (Properties / Compatibility) of the .exe. No good.
Created a .reg file to affect the HLKM\ ... \AppCompatFlags\Layers keys. Nada.
Tried affecting both the HKLM AND HKCU keys. Thank you, next.
Checked if some Recordset or variable was filled or active. Everything empty.
Tried Unload [name of the form] instead of Unload Me for one of the forms. Same result.
Part of the Unload code for one of the forms is as follows:
Private Sub cmdSalir_Click()
On Error GoTo ErrHandler
Dim frm As Form 'Identifica las formas a cerrar
For Each frm In Forms
If Not frm Is frmPoliza And Not frm Is MDIPrincipal Then
If Not frm Is frmAsegNoReclam And Not frm Is frmEndosoMedico Then _
Unload frm
End If
Next frm
gsPlan = ""
gmstrInstPagoInd = ""
gmstrCondEnv = ""
If IsFormLoaded("frmCotiza") = False Then
'gbInicio = True
End If
Unload Me
ErrHandler: 'APM 2019-01-31: Captura el error que se provoca al descargar la forma
If Err.Number <> 0 Then
MsgBox "Ocurrió un error al cerrar: " & Err.Number & " - " & Err.Description, vbOKOnly
End If
End Sub
It is important to say that WinXP's installations are working correctly, but in 2 Win10's computers the error was replicated, so I'm guessing either Win10's security policies or the way the installation package is made has something to do with this.
If you can help me with this issue, I will appreciate it greatly.
Thank you,
Tony.
If the issue is that you need to run with elevated rights, then I suggest you declare that in you application manifest such that the user is prompted grant that. You can either create a separate manifest file or embed it. See here for details:
How do I create a manifest file in Visual Basic 6.0?
So I told the client about this issue, and decided to have the program virtualized in XP better than adapted to x64. Not the closing I wanted, but a closing after all.
Thank you all for your efforts.
Not sure if this will fix the specific problem but have found that running the application in Windows 8 Compatibility Mode on Windows 10 helps with issues like this. Worth a try.
I have a VB6 project that I didn't create but I have to update, when I go to make the exe I get a compile error: Method or data member not found, and it points too "SCom1.FileReceive" in the code below. When I look at the Main form, the SCom1 control is a PictureBox.
This code has been working for the last 5 years but I don't know why SCom1 is a picturebox, or why I'm getting the error, is it a reference? SCom1 to me looks like a MSComm function? Let me know if anyone has any ideas, I just don't know VB enough to know how to troubleshoot this. Thanks
If SCom1.FileReceive = True Then
WriteToLog (Now() & " FileReceive was true, now false")
SCom1.FileReceive = False
End If
The machine which you have opened the code doesn't have the mscomm32.ocx file or the ocx file not registered properly.
When vb cannot reference an ocx, it'll convert the relevant control to a picture box control.
What you have to do is, close the project without saving. Then open system32 folder and check for mscomm32.ocx file. If the file is not there then you have to download that from the intenet. The register the file using regsvr32 command in command prompt.
After this you can open the vb6 project and start working.
=========================================================
EDIT : Included the update in the comments to the answer, this will help other users in the future... :-)
if the method name doesn't look familiar to a known ocx file (in this case the SCom1.FileReceive), the missing component can be a custom ocx file.
So check on the working machine or in project folder whether there are any ocx file exists in the relevant name (in this case SCom.ocx).
if there is a file exists in such name, register that file using regsvr32 (if not registered), then add that to toolbox, then replace the picture box control with the relevant control (make sure the name tally).
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
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?