Solved

check if file exist if not make one

Posted on 2010-11-16
9
609 Views
Last Modified: 2012-06-21
I need a vb script that can do the following steps please
1- check if a text file (an empty one) called Install.txt exist under %appdata%\org
2- if the file exist do nothing
3- If the the text file does not exist, create one under %appdata%\load\org then launch another vb script called load.vbs from C:\temp\

This where I got so far:

Dim sUserName
Dim sFileName
Dim sFile
Dim strFolder, objFSO
Set objWShell=CreateObject("Wscript.Shell")
Set objFSO=CreateObject("Scripting.FileSystemObject")
susrName=objWShell.expandEnvironmentStrings("%USERNAME%")
strFolder="C:\Documents and Settings\"&susrName&"\Application Data\load\Org"
sFileName=(strFolder & "\" & "Install.txt")
Set sFile=objFSO.CreateTextFile(sFileName, True)
Set objFSO=nothing
Set objShell=nothing
Set sFile=nothing

Thank you
0
Comment
Question by:JAWC
  • 7
  • 2
9 Comments
 
LVL 27

Expert Comment

by:KenMcF
Comment Utility

You can try something like this

Dim sUserName
Dim sFileName
Dim sFile
Dim strFolder, objFSO
Set objWShell=CreateObject("Wscript.Shell")
Set objFSO=CreateObject("Scripting.FileSystemObject")
susrName=objWShell.expandEnvironmentStrings("%USERNAME%")
strFolder="C:\Documents and Settings\"&susrName&"\Application Data\load\Org"
sFileName=(strFolder & "\" & "Install.txt")
If objFSO.FileExists(sFileName) Then
Wscript.quit
Else
Set sFile=objFSO.CreateTextFile(sFileName, True)
Set objFSO=nothing
Set objShell=nothing
Set sFile=nothing
End if


0
 

Author Comment

by:JAWC
Comment Utility
Thank you Ken, This is good but I will have to launch a vbscript after creating the text file

3- If the the text file does not exist, create one under %appdata%\load\org then launch another vb script called load.vbs from C:\temp\




0
 

Accepted Solution

by:
JAWC earned 0 total points
Comment Utility
I managed to make the script to work by doing the following

Dim sUserName
Dim sFileName
Dim sFile
Dim strFolder, objFSO
set WshShell = WScript.CreateObject("WScript.Shell" )
Set objWShell=CreateObject("Wscript.Shell")
Set objFSO=CreateObject("Scripting.FileSystemObject")
susrName=objWShell.expandEnvironmentStrings("%USERNAME%")
strFolder="C:\Documents and Settings\"&susrName&"\Application Data\load\Org"
sFileName=(strFolder & "\" & "Install.txt")
If objFSO.FileExists(sFileName) Then
Wscript.quit
Else
Set sFile=objFSO.CreateTextFile(sFileName, True)
wshshell.Run """C:\temp\load.vbs"""
Set objFSO=nothing
Set objShell=nothing
Set sFile=nothing
End if

Thank you Ken for trying
0
 
LVL 27

Expert Comment

by:KenMcF
Comment Utility
"I managed to sort the issue out", you used my solution your main issues of checking to see if the file exists and create on if it does not. The only thing I forgot to put in my post was to call the other vbs.
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Author Comment

by:JAWC
Comment Utility
Hi Ken.
If you look at my question I did add my own script:
Dim sUserName
Dim sFileName
Dim sFile
Dim strFolder, objFSO
Set objWShell=CreateObject("Wscript.Shell")
Set objFSO=CreateObject("Scripting.FileSystemObject")
susrName=objWShell.expandEnvironmentStrings("%USERNAME%")
strFolder="C:\Documents and Settings\"&susrName&"\Application Data\load\Org"
sFileName=(strFolder & "\" & "Install.txt")
Set sFile=objFSO.CreateTextFile(sFileName, True)
Set objFSO=nothing
Set objShell=nothing
Set sFile=nothing

Your script had the following line s add it to it:
If objFSO.FileExists(sFileName) Then
Wscript.quit
Else
Set sFile=objFSO.CreateTextFile(sFileName, True)

Which it was very much appreciated. I can not guess that you have forgotten to add the laucnh of the VB script.

Only because it is not worth arguing about things like this and I do appreciate you time and your assistance. I will give you the point even though it is too much for three lines.

Again thank you for your help.
0
 

Author Comment

by:JAWC
Comment Utility
Sorry I closed it with granting Ken points. please let me know how to do this . IDear Moderator could you sort this one out.

Thank you
0
 

Author Comment

by:JAWC
Comment Utility
Ken: I will make sure that you get the points. please take note of my earlier explaination
17/11/10 03:02 AM, ID: 3415387

Regards
0
 

Author Comment

by:JAWC
Comment Utility
Dear moderator please Grant ken the rewards point.

Thank you
0
 

Author Closing Comment

by:JAWC
Comment Utility
I have accepted my solution because I did comlete the script that I was looking for.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Step by step guide to Clean and Sort your windows registry! Introduction: Always remember: A Clean registry = Better performance = Save your invaluable time In this article we're going to clear our registry manually! Yes, manually! The e…
Issue: Unstable cursor in Windows XP and Windows runs extremely slow in that any click will bring up the Hour glass (sometimes for several seconds before giving you what you want) . Troubleshooting Process and the FINAL FIX: This issue see…
This video discusses moving either the default database or any database to a new volume.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now