VMware Horizon Community
btrabue
Enthusiast
Enthusiast
Jump to solution

Script nees minor modification for dedicated VM

I have the attached script that I need some help with.  It was created for a linked clone and will not work with a dedicated VM.  What is does is when the thinapp is first ran it will create a folder on the D drive and copy a file into the folder.  I'm asking for some help to create a folder on the C drive and copy the file into the same folder.  

0 Kudos
1 Solution

Accepted Solutions
kmgp
VMware Employee
VMware Employee
Jump to solution

Hi,
Looking at the logic of current implementation
For Check folder,
It checks if a folder D:\VAForms5 exists, if it does not it creates it.
For CopyFile
You are trying to see if a file like vvet5.mdb exists in C:\vaforms5 if Yes then you copy the file to D:\vaforms5.
Now for it to work with C:
1. You need to Change the variable strDrive to "C:\". It helps to create a folder c:\vaforms5 using "CheckFolder" routine.
2. To reuse the same script, file vvet5.mdb needs to be in a different location than c:\vaform5, because I am presuming the destination location cannot change.
Assuming the folder where the vvet5.mdb file initially exists in folder "test", the if condition in the "CopyFile" routine needs to change to
If objFSO.FileExists("C:\test\vvet5.mdb") then
'wscript.echo "Source file C:\test\vvet5.mdb does exist"
objFSO.CopyFile "C:\test\vvet5.mdb" , strFolder & "\vvet5.mdb",
OverwriteExisting
PS: Just changing the strDrive would have a Side-effect where source and destination location would be the same.
GURU
Views expressed in here are my own.

View solution in original post

0 Kudos
22 Replies
Lakshman
Champion
Champion
Jump to solution

Looking at the script, i think it copies the file to C:\VAForms5. Not very sure why it is going to D drive.

0 Kudos
btrabue
Enthusiast
Enthusiast
Jump to solution

Whoops. I copied the wrong script.  The script that I have working for a linked clone is attached.  Sorry about that.

0 Kudos
kmgp
VMware Employee
VMware Employee
Jump to solution

Hi,
Looking at the logic of current implementation
For Check folder,
It checks if a folder D:\VAForms5 exists, if it does not it creates it.
For CopyFile
You are trying to see if a file like vvet5.mdb exists in C:\vaforms5 if Yes then you copy the file to D:\vaforms5.
Now for it to work with C:
1. You need to Change the variable strDrive to "C:\". It helps to create a folder c:\vaforms5 using "CheckFolder" routine.
2. To reuse the same script, file vvet5.mdb needs to be in a different location than c:\vaform5, because I am presuming the destination location cannot change.
Assuming the folder where the vvet5.mdb file initially exists in folder "test", the if condition in the "CopyFile" routine needs to change to
If objFSO.FileExists("C:\test\vvet5.mdb") then
'wscript.echo "Source file C:\test\vvet5.mdb does exist"
objFSO.CopyFile "C:\test\vvet5.mdb" , strFolder & "\vvet5.mdb",
OverwriteExisting
PS: Just changing the strDrive would have a Side-effect where source and destination location would be the same.
GURU
Views expressed in here are my own.
0 Kudos
btrabue
Enthusiast
Enthusiast
Jump to solution

That was it!  Thank you for explaining how it worked.  I appreciate it.

0 Kudos
btrabue
Enthusiast
Enthusiast
Jump to solution

I tried adding Function OnFirstSandboxOwner to the top of the script and I am getting errors now.  I found out that the script would run everytime and erase the database that was in the folder on the C drive.  Any idea how to get the script attached to run correctly?  Thanks in advance.

0 Kudos
Lakshman
Champion
Champion
Jump to solution

Can you attach the script?

0 Kudos
btrabue
Enthusiast
Enthusiast
Jump to solution

Attached.  Sorry about that.

0 Kudos
Lakshman
Champion
Champion
Jump to solution

0 Kudos
btrabue
Enthusiast
Enthusiast
Jump to solution

I can understand that but why does it run and do what I want it to do?  I just need it to only run once instead of everytime the user opens the thinapp.

0 Kudos
kmgp
VMware Employee
VMware Employee
Jump to solution

See if this helps.



dim filesys
strDrive = "C:\"
strFolder = strDrive & "VAForms5" & "\"

sub CreateFolder
set filesys=CreateObject("Scripting.FileSystemObject")
If Not filesys.FolderExists(strFolder) Then
Set newfolder = filesys.CreateFolder(strFolder)
MsgBox "A New Folder is created successfully"
End If
End Sub

Sub CopyFile
set filesys=CreateObject("Scripting.FileSystemObject")
If filesys.FileExists("c:\vvet5.mdb") Then
MsgBox "File exists"
msgbox "copying c:\vvet.mdb to " & strFolder
filesys.CopyFile "c:\vvet5.mdb", strFolder
else
msgbox "The very required access database folder in c:\ by name vvet5.mdb is not found"
End If
End Sub

Function OnFirstSandboxOwner
msgbox "This application is for VMware Employee only!"
CreateFolder
CopyFile
End Function
Views expressed in here are my own.
kmgp
VMware Employee
VMware Employee
Jump to solution

You may change the messages in message boxes like what you need.

-GURU

Views expressed in here are my own.
0 Kudos
btrabue
Enthusiast
Enthusiast
Jump to solution

Exactly what I was looking for.  Just one favor, can you please remove the message boxes?  They popup everytime I run the thinapp and the users will not want to click on several times before the application finally opens.  A BIG thank you!!

0 Kudos
Lakshman
Champion
Champion
Jump to solution

I have modified your script, please see attached.

0 Kudos
btrabue
Enthusiast
Enthusiast
Jump to solution

I received an error the second time that the file already exists.  It says line 39, character 2.  

0 Kudos
kmgp
VMware Employee
VMware Employee
Jump to solution

Replace this line in the script

filesys.CopyFile "c:\vvet5.mdb"

with

filesys.CopyFile "c:\vvet5.mdb", strFolder,true

this will overwrite even if the file is existing

GURU

Views expressed in here are my own.
0 Kudos
btrabue
Enthusiast
Enthusiast
Jump to solution

If the file is there I don't want it over written.  Any new user that starts with the department needs to have the blank database and they add to it.  For current users we are taking the database from their desktop and copying it to the virtual comptuer.  A lot of users have many years of data in the database and it cannot be over written.   The only reason that this is being done this way is so that the user can see the folder on the drive and replace the current database with the one that they pull off of their other computer.  They also need to backup this database from time to time.  Hope that helps you.

0 Kudos
btrabue
Enthusiast
Enthusiast
Jump to solution

The below script works fine.  I just need help removing the message boxes that appear.  I was able to remove every message box except for the below section.

msgbox "copying c:\vvet.mdb to " & strFolder
filesys.CopyFile "c:\vvet5.mdb", strFolder

dim filesys
strDrive = "C:\"
strFolder = strDrive & "VAForms5" & "\"


sub CreateFolder
set filesys=CreateObject("Scripting.FileSystemObject")
If Not filesys.FolderExists(strFolder) Then
Set newfolder = filesys.CreateFolder(strFolder)
MsgBox "A New Folder is created successfully"
End If
End Sub


Sub CopyFile
set filesys=CreateObject("Scripting.FileSystemObject")
If filesys.FileExists("c:\vvet5.mdb") Then
MsgBox "File exists"
msgbox "copying c:\vvet.mdb to " & strFolder
filesys.CopyFile "c:\vvet5.mdb", strFolder
else
msgbox "The very required access database folder in c:\ by name vvet5.mdb is not found"
End If
End Sub


Function OnFirstSandboxOwner
msgbox "This application is for VMware Employee only!"
CreateFolder
CopyFile
End Function

0 Kudos
Lakshman
Champion
Champion
Jump to solution

Just delete that line or comment out by adding ' at the beginning.

'msgbox "copying c:\vvet.mdb to " & strFolder

btrabue
Enthusiast
Enthusiast
Jump to solution

wow, that was all that I had to do.  I was thinking too deep on that one.  Thank you again for both of your help!  Now this application can be deployed to Windows 7 users where as before it was only being used for XP only users.

0 Kudos