Windows CE 3.0: error when I try to create object to can copy files: - vbscript

I want to create a VBS script for a Windows CE device to copy some files from a SD card to a network folder. But I get this error: Error ActiveX component can't create object: 'CreateObject'
This is the code:
' Declaration of variable
Dim objFileSystem
' Create object for filesystem access
Set objFileSystem = CreateObject("Scripting.FileSystemObject")
' Copy folder
objFileSystem.CopyFolder "\storage card2\*", "\\PlcServer\csv"
' Deallocate filesystem object
Set objFileSystem = Nothing
The problem is when I try to create the FileSystemObject object.
Do I need to register or do something in the Windows CE device to can use this script?
Thanks.

Related

Set/adjust file version of a rtf-file with VBscript

I created a logon script to automatically create a email signature for Outlook. This script creates the following file "C:\Users\%username%\AppData\Roaming\Microsoft\Signatures\Default_signature.rtf"
I would like to add to a versionnumber to this file so I can check if an update of this file is necessary or not. If not, exit logon script. Else update signature with a higher versionnumber.
To get a versionnumber was pretty easy to find, but I couldn't find how to set/change a versionnumber with VBscript.
Using the DSOFile.OleDocumentProperties didn't work for me. I kept getting a ActiveX-error "Can't create object". It could be that I have to register
the dsofile.dll in the system but this code has to work for every user in our company and I don't want to install this on every device before I can use this logon script.
'Code for requesting versionnumber
Set objFSO = CreateObject("Scripting.FileSystemObject")
file = "C:\Users\%username%\AppData\Roaming\Microsoft\Signatures\Default_signature.rtf"
Wscript.Echo "Version = " & objFSO.GetFileVersion(file)
I hope someone could tell me how to do this :)
As far as i know DSO is the only supported way by Microsoft to change properties of the files without rewriting them. There are some VBA scripts out there for Excel, but that does not apply in your case with RTFs.
However, might i suggest a different alternative? I have in my infrastructure a script that is placed to run at each logon and checks on a share a certain file's last modified date. If the file present on the machine is older, then it's replaced by that on the share.
Dim objFSO, strFileName
strFileName = "C:\Users\user\Desktop\Tests\fdsfsd.rtf"
Set objFSO = CreateObject( "Scripting.FileSystemObject" )
WScript.Echo objFSO.GetFile( strFileName ).DateLastModified
Set objFSO = Nothing

vbscript create text file in server directory

I have vbscript application that run in a server and I tried run that application in my local computer. The problem is I want to create a text file in server directory but I always end up with an error something like "disk is not ready". When I check, it is because in my local computer, there is only 1 partition Drive C: and for some reason the application try to make the textfile in my local directory. And if change the path to drive C: it works and the file is existed in my local directory. So what am I doing wrong? I want the text file is created in server directory.
Here's part of my code :
Dim fso, MyFile
Set fso = CreateObject("Scripting.FileSystemObject")
Set MyFile = fso.CreateTextFile("D:\tesfolder\SomeText.txt", True)
MyFile.WriteLine("This is a test.")
MyFile.Close
Set MyFile = Nothing
Set fso = Nothing
please help me
Set fso = CreateObject("Scripting.FileSystemObject")
Set MyFile = fso.CreateTextFile("\\127.0.0.1\C$\SomeText.txt", True)
MyFile.WriteLine("This is a test.")
MyFile.Close
The above needs Admin because it uses the Admin only share (present on all computers) c$ and writes to the root of C: drive.
The format is
\\ServerName(orIP)\ShareName\Folder\File.ext
An admin would
\\Computer\D$\tesfolder\SomeText.txt
For a user substitute their share name for D$.

Alias error in VBS

How to use alias in VBScript? I am trying following code:
AliasesExample
Sub AliasesExample
Dim AliasObj
' Obtains the object that corresponds to the Notepad main window
Set AliasObj = Aliases.notepad.wndNotepad
' Checks whether the specified window exists
If AliasObj.Exists Then
' Enters text in the Notepad editor
AliasObj.Keys("Hello, world.")
Else
Log.Error("Notepad is not running.")
End If
End Sub
but getting the following error:
object required: 'Aliases'
VBScript and Windows Script Host do not support calling DLL and Windows API functions, but there're some possible solutions:
You can call DLL functions that are exposed through COM objects:
Set obj = CreateObject("Foo.Bar")
Call obj.Method(Param1, Param2)
You may be able to call some DLL functions using rundll32 if the DLL and the function meet certain requirements.
' Open "Programs and Features" using the Control_RunDLL function from shell32.dll
Set oShell = CreateObject("WScript.Shell")
oShell.Run "rundll32.exe shell32.dll Control_RunDLL appwiz.cpl,,0"
Other than that, you're out of luck.
So generally, you need a COM-callable wrapper for your DLL function to be able to use it from VBScript.

how to access a network folder using vbscript

I have a folder which is on a network like \\server\contents\tasks and I want to access this folder.
I am getting a "path not found" exception. What am I doing wrong here:
Dim FolderPath
FolderPath = "\\server\contents\tasks"
set FSO = CreateObject("Scripting.FileSyatemObject")
FSO.GetFolder(FolderPath)
Thanks
Edit: I found this post which answers the same thing I am trying to achieve, but the issue is I am getting an error the network share is no longer available. What I have is a local folder as a shared folder and mapped as \\servername\contents\tasks but it gives me the above error.
Edit: I was pointing at the wrong folder.
Now I have another issue trying to open a text file in the network folder. It is able to create a folder at the network path but throwing error while reading a text file in the network folder. Is there something else that needs to be done?
Set FSO = CreateObject("Scripting.FileSystemObject")
strOutputPath = strOutput1 --this is a network path
Set txsOutput = FSO.CreateTextFile(strOutputPath)
Set f = FSO.OpenTextFile(strInput1)
Open the network folder using explorer.exe and pass the location of the folder as a parameter (in this example it's sPath storing the folder path)
Example:
sPath = "\\somedrive.somecompany.ie\software"
Set oShell = CreateObject("WScript.Shell")
oShell.Run "explorer /n," & sPath, 1, False
Terms and conditions: username and password privileges already setup for acccess to the network folder.

vbscript to copy file from an external disk

A friend and I started building a VBScript that with the goal to copy any opened files/some specific format of docs (like pdf, pptx) when we insert an external hard disk or USB on the computer. We got our script as far as only copying all docs of a specific format from one the external hard disk/USB to my computer, but we must manually execute the script after inserting the external hard disk/USB.
What we would like the script to do:
Start automatically when an external hard disk/USB is inserted
Don't show a pop up after the copy
Possibily only copy the files (pdf,jpeg,pptx) that are opened by the user
Here is what we've done so far:
' foreach.vbs
' Testing the for each function on files
'
' BEGIN
' Create a File System Object to handle files and folders
Set fso = CreateObject("Scripting.FileSystemObject")
' Some vars
src = "C:\" ' The source of search, should be changed before use
dest = "c:\temp\1\" ' destination where we will copy files to
' It would be a bright idead to force and/or create dest before
' starting copy
fso.CreateFolder(dest)
Set ofolder = fso.GetFolder(src) ' set as object
' get all files inside the specified folder
Set allfiles = ofolder.Files
' Enter a For Each Loop that will process each of the files
For Each sfile in allfiles
' Better get all extensions in lower case
If LCASE(fso.GetExtensionName(sfile.Name)) = "bat" then
' Print out what we find
wscript.echo sfile.Name
fso.CopyFile sfile, dest
End If
Next
If I get it right, your actual question is How to detect a USB drive has been plugged in?
You'll need some event driven language to do this, not VBScript unfortunately.
But if you don't want to go with programming, why not using Task Scheduler.
P.S. Actually, this topic (I not like the infinite cycle, but) is a possible answer.

Resources