Copy file using vbscript

Label printing integration (NiceWatch middleware and ActiveX programming interface)

Moderators: Georges, milos, NiceLabel Support Team

Post Reply
Mikael
Enthusiast
Posts: 9
Joined: Mon May 05, 2014 4:22 pm

Copy file using vbscript

Post by Mikael » Wed Oct 02, 2019 4:34 pm

Hi,

I´m trying to copy a file using vbscript. First the user picks a file using "Browse for file or folder". Then we pass that into a variable. But when I try to use that variable in my fso.FileCopy vbscripts it doesn´t work, it says it´s in wrong format.

Please help!

User avatar
Mytch
NiceLabel Support
NiceLabel Support
Posts: 68
Joined: Fri Jul 13, 2018 10:26 pm
Location: Milwaukee, Wisconsin
Contact:

Re: Copy file using vbscript

Post by Mytch » Wed Oct 02, 2019 8:19 pm

Mikael,

Can you please post your VBScript that is used to accomplish this? Or perhaps attach the related Solution?

Please be sure that you are defining a full UNC path with the file name, that the path is already existing at time of copy, no file exists with the same name (unless overwrite parameter is true), there are no white-spaces or invalid characters, etc. You should be able to do something simple like:

Code: Select all

fso.CopyFile [yourpathvariable], "C:\your\existing\path"
Regards,
Mytch

Mikael
Enthusiast
Posts: 9
Joined: Mon May 05, 2014 4:22 pm

Re: Copy file using vbscript

Post by Mikael » Thu Oct 03, 2019 2:42 pm

Thanks for your reply!

If i run this, it works:

Set fso = CreateObject("Scripting.FileSystemObject")
fso.CopyFile "\\somepath\file.txt", "\\DestinationPath\folder\"

But if I substitute UNC with Varialble containing the exact same path it fails:

Set fso = CreateObject("Scripting.FileSystemObject")
fso.CopyFile VariableName, "\\DestinationPath\folder\"

If I do "Check Script" It fails with:

Error ID: 92003
Error description: 'Script error:'
Detailed information: 'Inkompatibla typer: 'fso.CopyFile'
Line number: 2'
Possible solution: ''
Severity ID: 3
Severity name: 'Error'
Available actions: OK
Default action: OK
Group ID: 17
Type ID: 2
Can disable dialog: NO

And If I run it from a button it fails with:

Error ID: 200007
Error description: 'Script error:
Det går inte att hitta angiven sökväg. (Translation=Can´t find path..)
Line number: 2
Column number: 0'
Detailed information: 'Error executing action: 3.
Run the editor in Advanced mode to identify the action which caused the error in the action editor. An action ID will be displayed next to the action.
'
Possible solution: ''
Severity ID: 3
Severity name: 'Error'
Available actions: OK
Default action: OK
Group ID: 17
Type ID: 1
Can disable dialog: NO


So I interpret this as the script tries to read the name of the variable as a path and noth what is stored in the varaible?

//Mikael

User avatar
Mytch
NiceLabel Support
NiceLabel Support
Posts: 68
Joined: Fri Jul 13, 2018 10:26 pm
Location: Milwaukee, Wisconsin
Contact:

Re: Copy file using vbscript

Post by Mytch » Thu Oct 03, 2019 4:20 pm

Mikael,

Firstly, yes your Verify Script will fail. This is because you do not set your variable until you run the Solution and browse to the file. So how can the script know the value of your variable at time of testing? It can't.

Secondly, if you are trying to use a NiceLabel variable within VBScript, you should use the "Insert Data Source" button, which will add the variable with the format like [variableName]. This is the proper way to reference a NiceLabel variable. Please check the sample that I have attached.

If any issues persist, please update to the latest version of NiceLabel 2017 or NiceLabel 2019 (whatever you have a license for)?:
http://ftp.nicelabel.com/software/demo/ ... el2017.exe
http://ftp.nicelabel.com/software/demo/ ... el2019.exe

Thanks,
Mytch
Attachments
copyFile.nsln
(3.71 KiB) Downloaded 21 times

Mikael
Enthusiast
Posts: 9
Joined: Mon May 05, 2014 4:22 pm

Re: Copy file using vbscript

Post by Mikael » Fri Oct 04, 2019 3:12 pm

Hi,

I understand that I need a value for it to work. Therefore I created a dummy variable in NiceForm with a set value and used that for testing while building the script.

Anyhow, I don´t have that button, I´m running an older version of NiceLabel. I can pick the variable from a list in the Build script windows. And when I do it doesnt add the variabel with []. But I´ll try your suggestion and enter the name between [] and see if that help. Otherwise I need to update NiceLabel perhaps.

Thanks.

Mikael
Enthusiast
Posts: 9
Joined: Mon May 05, 2014 4:22 pm

Re: Copy file using vbscript

Post by Mikael » Fri Oct 04, 2019 3:29 pm

UPDATE: No it didn´t work. I guess I need to update NiceLabel.

Is it possible to have different versions of NiceLabel installed on the same PC? I would like to use the newest version availiable to me for developing new label Projects. But I need the older for Projects that are validated using a specific version.

/Mikael

User avatar
Mytch
NiceLabel Support
NiceLabel Support
Posts: 68
Joined: Fri Jul 13, 2018 10:26 pm
Location: Milwaukee, Wisconsin
Contact:

Re: Copy file using vbscript

Post by Mytch » Fri Oct 04, 2019 5:41 pm

Mikael,

Sorry for any confusions, I had not considered you were using a legacy version of NiceLabel (probably NiceLabel 6). We have tested this successfully with NiceLabel 2017.3.1 and NiceLabel 2019.1.1 (latest version of each release). Unfortunately, we have stopped supporting NiceLabel 6 as of December 2018. However, you are free to use the program and continue to request supported through our Forums, if someone out there is willing to troubleshoot NiceLabel 6 VBScript. :)

Please note that is it possible to have NiceLabel 6 and NiceLabel 2019 installed on the same machine (different code-base). However, it is not possible to use something like NiceLabel 2017 and NiceLabel 2019 on the same machine (same code-base).

Regards,
Mytch

Mikael
Enthusiast
Posts: 9
Joined: Mon May 05, 2014 4:22 pm

Re: Copy file using vbscript

Post by Mikael » Mon Oct 07, 2019 9:15 am

That´s fine. I understand that version 6 is not supported still and I should have said that what was I was using. I have a licenses for NL 2019 so I´ll go ahead and install that for this Project. Thank you for your help.

//Mikael

Mikael
Enthusiast
Posts: 9
Joined: Mon May 05, 2014 4:22 pm

Re: Copy file using vbscript

Post by Mikael » Mon Oct 07, 2019 10:46 am

Ok, so I installed version 2019. I tried your script but it fails with "access denied" when I hit execute. DO I need to set credentials somewhere for it to be able to copy a file?

/Miikael

User avatar
Mytch
NiceLabel Support
NiceLabel Support
Posts: 68
Joined: Fri Jul 13, 2018 10:26 pm
Location: Milwaukee, Wisconsin
Contact:

Re: Copy file using vbscript

Post by Mytch » Mon Oct 07, 2019 5:26 pm

Mikael,

Firstly, please try to Unblock the Solution file that you have downloaded. Some restricted environments may require an externally downloaded file to be Unblocked prior to full usage. You can do so by right-clicking the copyFile.nsln file, selecting Properties, and checking the Unblock box (or clicking the Unblock button on older operating systems), then Apply the changes and click OK. See below for example:
screenshot_14.jpg
screenshot_14.jpg (55.66 KiB) Viewed 107 times
If the file still have permissions problems, you can try to save the Solution somewhere locally with a new name and run again. Finally, you must of course be having permissions to the origin and destination files/directories. The user running the provided solution must be having proper security permissions to both defined directories, otherwise the copy process will fail.

Hopefully this resolves your issue.

Regards,
Mytch

Mikael
Enthusiast
Posts: 9
Joined: Mon May 05, 2014 4:22 pm

Re: Copy file using vbscript

Post by Mikael » Tue Oct 08, 2019 8:51 am

Hi,

No that is not the problem. I have full access to the files/folder I´m trying with. And when I try to run the script in my own Project I get the same error.

Basically it reads:

An error occured when "Execute Script (1)" ran.

System error message:
Access Denied.

UPDATE:

I tired doing something basic like MSGBOX([Variable]) and that work fine. SO it´s interacting with files and folders that fails. The user starting the Form, it must be with that users permissions the script runs right? Because the user has full access to what I´m trying to do. I´ve tried both with network folders and local folders. Same result. Access Denied.

I´ll try to run scripts outside of NiceLabel and see if it fails there also.

UPDATE 2:

Running the script in a .vbs file works fine. It´s just in a form in NiceLabel it fails with access denied. :-(

UPDATE 3:

Ok, finally got this to work. Was a problem with "" around the path.

Thanks for all your help!

//Mikael

User avatar
Mytch
NiceLabel Support
NiceLabel Support
Posts: 68
Joined: Fri Jul 13, 2018 10:26 pm
Location: Milwaukee, Wisconsin
Contact:

Re: Copy file using vbscript

Post by Mytch » Tue Oct 08, 2019 3:03 pm

Mikael,

Thanks for the update - glad to hear you got it working.

Regards,
Mytch

Post Reply