• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 755
  • Last Modified:

vbscript - if FolderExists question

Not sure what is going on with this script. I am trying to grab data from each users application data folder. If the file exists then echo. If you want to test then you can put a known folder.

Option Explicit

'Variables
Dim objShell,FSO
Dim strUserProfile,strAppData,objFile


Wscript.echo "working so far"

' Get the current users profile folder
Set objShell = CreateObject("WScript.Shell")
strUserProfile=objShell.ExpandEnvironmentStrings("%USERPROFILE%")
strAppData=objShell.ExpandEnvironmentStrings("%APPDATA%")
' Set reference to the file system
Set FSO = createobject("Scripting.FileSystemObject")

' Check if each folder exists.

If FSO.FolderExists(strUserProfile & strAppData) & "\Microsoft" = True Then
WScript.Echo "im here"
Else
WScript.Echo "not here"
End If
0
rrangel8
Asked:
rrangel8
  • 6
  • 4
1 Solution
 
rlandquistCommented:
%USERPROFILE% = C:\Users\YOURNAME
%APPDATA% = C:\Users\YOURNAME\AppData

So you are saying you are looking for a folder named:
C:\Users\YOURNAMEC:\Users\YOURNAME\AppData\Microsoft

You just need
If FSO.FolderExists(strAppData) & "\Microsoft" = True Then

To check variable locations open a command prompt and type set and press enter


0
 
rrangel8Author Commented:
this should work for all users with a profile on a machine.
0
 
rlandquistCommented:
Oh, then you need to approach this a little different.

Try this:
'Create Objects
Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")

'Get special folder paths
strAllUserProfile = objShell.ExpandEnvironmentStrings("%USERPROFILE%")

'Get Path of profile folder
strAllProfiles = objFSO.GetParentFolderName(strAllUserProfile)
Set objProfiles = objFSO.GetFolder(strAllProfiles)

'Exclude System Default Profiles
Set SkipProfilesArray = CreateObject("Scripting.Dictionary")
SkipProfilesArray.Add "Administrator", "Administrator"
SkipProfilesArray.Add "All Users", "All Users"
SkipProfilesArray.Add "Default User", "Default User"
SkipProfilesArray.Add "LocalService", "LocalService"
SkipProfilesArray.Add "NetworkService", "NetworkService"

'Check date of ntuser.dat in each profile folder and delete if criteria meet
For Each strUserProfile In objProfiles.SubFolders
    If Not SkipProfilesArray.Exists(strUserProfile.Name) Then
        If objFSO.FolderExists(strUserProfile & "\Desktop") Then
            WScript.Echo "Folder Found for " & strUserProfile.Name
        Else
            WScript.Echo "Folder Missing or No Access for " & strUserProfile.Name
        End If
    End If
Next

WScript.Echo VbCrLf & "Script Finished"

Open in new window

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
rrangel8Author Commented:
sorry guys...i was out of the office Friday. will test out today.

appreciate your help!
0
 
rrangel8Author Commented:
RLANDQUIST,

thanks for the input. I copied and pasted the script on my VM. I changed the name of the folder to a known existing folder in each users profile in Application Data and it did not pick up the folder. What do you think? I have funk software, ICA CLIENT IDENTITIES, MICROSOFT, VANDYKE, WINBATCH in the application data folder and didn't pick up any of these.

0
 
rrangel8Author Commented:
RLANDQUIST,

thanks for the input. I copied and pasted the script on my VM. I changed the name of the folder to a known existing folder in each users profile in Application Data and it did not pick up the folder. What do you think? I have funk software, ICA CLIENT IDENTITIES, MICROSOFT, VANDYKE, WINBATCH in the application data folder and didn't pick up any of these.

0
 
rlandquistCommented:
That is because you are going further down the tree.  In my script, Desktop is at the same level as Application Data.

Try replacing \Desktop with \Application Data\Microsoft

Let me know how that goes.
0
 
rrangel8Author Commented:
ahhh...i tried it earlier with "application data\microsoft" not like yours "\application data\microsoft"

Your the man.

So, let me expand on this if you will. Will this same logic work for FILES?
0
 
rlandquistCommented:
Yes.
0
 
rrangel8Author Commented:
th
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now