Skip to content

Create a detection rule using the user variable

Featured Replies

Hi,

 

I work with SCCM 2012 SP1 and I would like to create an application that deploy files in the user profile.

However, I'm stuck on the detection method because I can not use the variable %USERPROFILE% or %USERNAME%. (view picture 1 and 2)

However, SCCM knows other variables such as "%windir%" or "%ProgramFiles%" (view picture 3)

 

Someone has an idea

post-19579-0-62374300-1363702282_thumb.png

post-19579-0-57164500-1363702304_thumb.png

post-19579-0-71113200-1363702318_thumb.png

  • 2 weeks later...
  • Author

Hi,

 

For information, use custom scripts with return codes:

 

http://technet.microsoft.com/en-us/library/gg682174.aspx

 

Here is the VBS script that I created to verify the presence of a file in the user profile:

 

        '** Déclaration des variables
    Dim oFSO

        '** Déclaration des objets
    Set oFSO = CreateObject("Scripting.FileSystemObject")
    Set WshShellObj = WScript.CreateObject("WScript.Shell")
    Set WshProcessEnv = WshShellObj.Environment("Process")

        '** Affectation des variables
    UserProfile = WshProcessEnv("USERPROFILE")
    FileName = WScript.ScriptFullName
    Set InfoVbs = oFSO.GetFile(FileName)
    RepCourant = InfoVbs.ParentFolder        'Sans le "\" de la fin
    FichierFlag = UserProfile &"\AppData\Roaming\Test\FichierTesteur.txt"

    If oFSO.FileExists(FichierFlag) Then
        WScript.StdOut.Write "The application is installed"
        WScript.Quit(0)
    Else
        WScript.Quit(0)
    End If
 

Bye

  • 2 months later...

Good start cravion. Your script seems a bit excessive though. Here's a quicker version that should do the same thing. Also, AppData location may be changed ... so use %AppData%.

Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oShell = WScript.CreateObject("WScript.Shell")

If oFSO.FileExists(oShell.ExpandEnvironmentStrings("%AppData%\Roaming\Test\FichierTesteur.txt")) Then
    WScript.StdOut.Write "The application is installed"
    WScript.Quit(0)
Else
    WScript.Quit(0)
End If

I used for my Dropbox detection script:

Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oShell = WScript.CreateObject("WScript.Shell")

If oFSO.FolderExists(oShell.ExpandEnvironmentStrings("%AppData%\Dropbox\bin")) Then
    WScript.StdOut.Write "Dropbox is Installed"
    WScript.Quit(0)
Else
    WScript.StdErr.Write "Dropbox is NOT Installed"
    WScript.Quit(0)
End If

Testing it now ... thanks!

 

  • 3 months later...

Hi VertigoRay

 

Had the task of getting DropBox packaged today for use via the App Catalog. Once again Windows-noob has been the resource used for this.

The above script had to be edited slightly for the installation to be successful. The script that worked for me was:

 

Set oFSO = CreateObject("Scripting.FileSystemObject")

Set oShell = WScript.CreateObject("WScript.Shell")

If oFSO.FolderExists(oShell.ExpandEnvironmentStrings("%AppData%\Dropbox\bin")) Then

WScript.StdOut.Write "Dropbox is Installed" WScript.Quit(0)

End If

 

If the part below is left in the application fails to start once requested.

 

Else

WScript.StdErr.Write "Dropbox is NOT Installed" WScript.Quit(0)

 

 

The edited script still detects the application and the installation is also successful due to a proper detection method specified!!

So cheers for the detection script...otherwise I'd still be banging my head against the wall.. :)

  • 11 months later...

I am trying to create a query that will do something similar. I am trying to find any machines that have the file "GalContacts.db" present in any of the sub folders of this location;

 

%userprofile%\AppData\Local\Microsoft\Office\15.0\Lync

 

Can anyone help with this?

 

Thanks

Kevin

This schould work

$ErrorActionPreference = "Stop"
$lpath = $env:LOCALAPPDATA + "\Microsoft\Office\15.0\Lync"
if(Test-Path $lpath){
    $result = gci $lpath -Recurse  -filter  "GalContacts.db"
}
if($result){return $true}

Is there a way to get a last modified date of the file "GALContact.db"? Also how do I deploy this script, is this something I put in compliance settings or can I put it in a query?

 

Thanks

Kevin

$ErrorActionPreference = "Stop"
$lpath = $env:LOCALAPPDATA + "\Microsoft\Office\15.0\Lync"
if(Test-Path $lpath){
    $result = gci $lpath -Recurse  -filter  "GalContacts.db" 
    $mdate = $result.LastWriteTime.ToString("yyyMMdd")
}
if($mdate -ge "20140822" ){return $true}

This will compare the last modified value with your defined value ( >= 08-22-2014 ).

The script is for a detection rule (custom script -> powershell)

 

If you want to fill collection based on the result, you need to modify the script by an additional line "else {return $false}" at the end. Then you can create a compliance rule (boolean).

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.