compliance setting doesn't works - sccm

I have some trouble to make a compliance setting rule, i would like to detect if an application is present in the appdata\local of all my users.
I have made some test, in first i have try with a powershell script :
$ExecutablePath = "C:\Users\$env:username\AppData\Local\ClickShare\Clickshare.exe"
if (Test-Path $ExecutablePath) {
Write-Output "ClickShare est installé."
} else {
Write-Output "ClickShare n'est pas installé."
}
No luck for know it's don't works this way (maybe I'm doing wrong with my script).
All the results are in the conform section but It's not true...
After that I have try with a direct path like :
%USERPROFILE%\AppData\Local\clickshare
It's don't work too... I have all the result in "non conform" but I have the application on my computer and it's in "non conform" or it should be in the "conforme" section ...
Have you some script or way working for detect if an application is present in the appdata\local ?
H have tried all what I have said below :)

Related

how to get rid of present working directory in powershell

I am working on a project that is buried deep beneath the folders and directories and because of that my powershell's line is half filled with the path to the directory. I want to know if it is possible to get rid of the long string of directory path that is constantly showing.
Add this to your script, then call the function after starting your script.
function prompt {
$p = Split-Path -leaf -path (Get-Location)
"$p> "
}
This way only the "leaf" folder will be shown for the prompt placeholder.
Building on the last answer I usually put the current path in the title bar of the console window and use the history ID for the prompt. Something like:
Function Prompt
{
$cwd = (get-location).Path
$LastHist = ( Get-History)[-1].Id + 1
$Host.UI.RawUI.WindowTitle = "SPoSh_$($PSVersionTable.PSVersion.Major) - $cwd | User: $($env:USERNAME)"
$Host.UI.Write("Green", $Host.UI.RawUI.BackGroundColor, "SPoSh_$($PSVersionTable.PSVersion.Major)")
" #$LastHist : "
}
So this would look like:
"SPoSh_5 #1 : "
I leave a space at the end which makes it easier to double click select a previous command without capturing any of the prompt itself.
Note: If you are working in the regular console the title bar additions let you know where you are without crowding the prompt.
The title bar stuff doesn't show in some of the other non-colsole PowerShell hosts, like VSCode's integrated console, but during script dev the location is usually fairly static, so it's not too much trouble.

Downloading and opening a series of image urls

What I am trying to do is download 2 images from URL's and open them after download. Here's what I have:
#echo off
set files='https://cdn.suwalls.com/wallpapers/cars/mclaren-f1-gtr-42852-400x250.jpg','http://www.dubmagazine.com/home/media/k2/galleries/9012/GTR_0006_EM-2014-12-21_04_GTR_007.jpg'
powershell "(%files%)|foreach{$fileName='%TEMP%'+(Split-Path -Path $_ -Leaf);(new-object System.Net.WebClient).DownloadFile($_,$fileName);Invoke-Item $fileName;}"
Im getting 'Cannot find drive' A drive with the name 'https' cannot be found.
It's the Split-path command that is having problems but cant seem to find a solution.
You could get away with basic string manipulation but, if the option is available, I would opt for using anything else that is data aware. In your case you could use the [uri] type accelerator to help with these. I would also just opt for pure PowerShell instead of splitting between batch and PS.
$urls = 'https://cdn.suwalls.com/wallpapers/cars/mclaren-f1-gtr-42852-400x250.jpg',
'http://www.dubmagazine.com/home/media/k2/galleries/9012/GTR_0006_EM-2014-12-21_04_GTR_007.jpg'
$urls | ForEach-Object{
$uri = [uri]$_
Invoke-WebRequest $_ -OutFile ([io.path]::combine($env:TEMP,$uri.Segments[-1]))
}
Segments will get you the last portion of the url which is a proper file name in your case. Combine() will build the target destination path for you. Feel free to add you invoke item logic of course.
This also lacks error handling if the url cannot be accessed or what not. So be aware of that possibility. The code above was meant to be brief to give direction.

Windows Batch script to read pom.properties file within .jar

I'm looking for a simple way to read the 2nd line of the pom.properties file that is placed within the META-INF folder of a compiled .jar. (see here: http://maven.apache.org/guides/getting-started/index.html#How_do_I_add_resources_to_my_JAR). I often need to know the date in that file and it's just a pain to have to open the jar every time and dig down into it. I want a Windows batch script that I can run via right-clicking on a .jar (so I'll need help with the Windows registry command as well). The result of the batch command can just be displayed in a cmd window (a nice bonus would be the value being copied to the clipboard, too).
In short: I want to be able to right-click on a .jar file in Windows Explorer > select 'Get Maven Generated Date' (or whatever) > and have the 2nd line of the pom.properties file printed to the console (and copied to the clipboard).
I know this can't be too hard, I just don't know quite what to look for :).
Thanks in advance for any help.
Note that .NETv4.5 is required to use the System.IO.Compression.FileSystem class.
Add-Type -As System.IO.Compression.FileSystem;
$sourceJar = <source-jar-here>;
$jarArchive = [IO.Compression.ZipFile]::OpenRead($sourceJar).Entries
try
{
foreach($archiveEntry in $jarArchive)
{
if($archiveEntry.Name -like "*pom.properties")
{
$tempFile = [System.IO.Path]::GetTempFileName()
try
{
[System.IO.Compression.ZipFileExtensions]::ExtractToFile($archiveEntry, $tempFile, $true)
$mavenDate = Get-Content $tempFile -First 2
Write-Host $mavenDate
}
finally
{
Remove-Item $tempFile
}
}
}
}
finally
{
$jarArchive.Dispose
}

I'm running a PHP script using WAMP, in this case how can I read files from My Documents?

I have a web application that reads files from its local directory (in wamp/www/). This file needed to be accessed by several users so I synced and shared it using Dropbox. Now, is there a shortcut I can use in php commands such as fwrite such that the code is not strictly applicable to only one computer?
For example, I can't code it to fwrite("C:\Users\name\My Documents\") because that is pretty specific to one user and long. I was wondering if there was a shorthand I can use, like %appdata% or %programfiles%?
Try using
$_SERVER['HOMEDRIVE'] and $_SERVER['HOMEPATH']
For drive and path to user folder respectively
print_r($_SERVER)
Will display all the environment variables. There you can see which one to select.
$fp = fopen("{$_ENV['USERPROFILE']}\My Documents\somefile.txt", 'wb');
See $_ENV on the manual and also getenv().
Please note this will only work in limited circumstances. You can use this internal function instead:
#include<Shlobj.h>
PHP_FUNCTION(win_get_desktop_folder)
{
char szPath[MAX_PATH];
if (zend_parse_parameters_none() == FAILURE)
RETURN_NULL();
if (SUCCEEDED(SHGetSpecialFolderPathA(NULL, szPath,
CSIDL_MYDOCUMENTS, FALSE))) {
RETURN_STRING(szPath, 1);
} else {
RETURN_FALSE;
}
}

How to debug browser hang during upload

I am writing a simple file uploader in CodeIgniter 2.0.2. Pasting code below.
Under certain conditions the browser hangs during this upload and I get "waiting for localhost" in the browser status bar (identical behavior in FF and Chrome).
I have verified that the file is being uploaded to the Windows temporary folder (the complete file), but the process gets stuck after that.
It appears that the condition for the bug is file size. But my php.ini has all the right settings for uploading files, and I still get the hang with a 700k file.
This bug occurs only when I run it on Windows 7 Apache, not on an Ubuntu box.
The suggested to me that some paths in the php.ini may be incorrectly set.
Apache log files have not been much help here because there is no error thrown.
I have tried using Chrome developer panel to debug but haven't turned up anything useful.
I am currently trying to get XDebug working, but since no error is thrown and the process doesn't complete, my expectations are low.
Any suggestions for how to trace this bug?
If there are specific php.ini settings you'd like to see, let me know, don't want to do the big dump.
Controller:
function do_upload_sql(){
// create directory
if (! is_dir(BACKUP_DIR)) {
mkdir(BACKUP_DIR, 0777);
}
// or if it exists and has restricted file permissions, change them
elseif(fileperms(BACKUP_DIR)!=0777){
chmod(BACKUP_DIR, 0777);
}
$config['upload_path'] = BACKUP_DIR;
$config['allowed_types'] = 'backup'; // an SQL backup file type
$config['overwrite'] = TRUE;
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload()) // this is the native CI function, probably where the problem is. I can provide some of that code if anyone wants.
{
$data['action'] = 'c_backup_restore/do_upload_sql';
$tab_error = array('error' => $this->upload->display_errors());
$data['error'] = $tab_error['error'];
$this->load->view('common/header');
$this->load->view('v_upload_sql', $data);
}
else
{
echo "success"; // yes it's getting here, but i get no file!
$data = array('upload_data' => $this->upload->data());
$file_upload = $data["upload_data"];
$this->restore_backup($file_upload); // go do something useful with the file
}
}
View:
<p>Select the backup file</p>
<div class="not_success"><?php echo $error;?></div>
<?php echo form_open_multipart($action);?>
<input type="file" name="userfile" size="30" />
<input type="submit" value="Upload" />
</form>
If your error only occurs on windows 7 apache, I think that your issue may be with the "is_dir()" "mkdir()" and "chmod()" commands -- these terminal commands are linux specific and will not work so great on a windows system.
I looked up the documentation on the mkdir() function in the PHP.net Manual at:
http://us.php.net/manual/en/function.mkdir.php
I found this in the comments section:
kendsnyder at gmail dot com 04-May-2007 08:17
When creating directories in Windows, trailing periods (".") are ignored. for example:
<?php
mkdir('c:/Buck Jr.',0755); // on Windows creates "c:/Buck Jr"
mkdir('c:/Elipses...',0755); // on Windows creates "c:/Elipses"
mkdir('c:/php.com',0755); // on Windows creates "c:/php.com"
?>
This is a Window's quirk, not a php shortcoming--meaning that you get the same results from a Window's command prompt.
So it seems it will work... but you are likely to have to futz with it to find the flavor that Windows systems prefer. Also it seems that you must specify the root drive on which to make the directory, e.g.: 'c:\somedir'
Also of interest, I did a quick google search and discovered that PHP has published a bug around the functionality you are using, specifically related to forward vs. back slashes of the windows vs. linux systems:
https://bugs.php.net/bug.php?id=29797
Here is a StackOverflow post related to your question:
PHP mkdir(), chmod() and Windows
So to summarize:
On a windows based web server, include the drive that the directory will be placed on
File Permissions on Windows are different from Linux (Windows doesn't have a chmod or file permissions structure like Linux!) Although from what I can tell Windows is supposed give a folder the equivalent of a 777 permissions level -- but this functionality seems buggy and error prone. But this also means that using the chmod() function on a windows system, you will get unpredictable results. For more info consult the PHP Manual: http://php.net/manual/en/function.chmod.php
Remember to use backslashes rather than forward slashes for the directory path, as Windows systems use back slashes, whereas Linux uses forward slashes.
When PHP creates a directory it uses the permissions that were granted to the user account that PHP is running under, which means that you may have to dig into windows to find what user permissions level your windows 7 Apache/PHP is running under and make that change there. I know, what a pain, right?
One final thing: mkdir() function returns true if the directory creation was successful and false if not -- you may want to be testing for that condition before proceeding with the rest of your code, because if the directory doesn't properly get created, all the rest of your code that relies on that directory existing is going to fail. Ultimately I think your browser is hanging upon submit because it is trying to access a function through PHP which there is no support for on Windows (chmod). Perform the function calls within a "Try/Catch" block to catch any exceptions that occur so that you can print them to screen or a log file if necessary:
$proceed = false;
try
{
// create directory
if (! is_dir(BACKUP_DIR)) {
$proceed = mkdir(BACKUP_DIR, 0777);
}
// or if it exists and has restricted file permissions, change them
elseif(fileperms(BACKUP_DIR)!=0777){
$proceed = chmod(BACKUP_DIR, 0777);
}
}
catch(Exception $e)
{
echo $e->message;
}
if($proceed == TRUE)
{
/*Proceed with your code*/
}
else
{
/*Gracefully fail*/
}
Good luck man, this is why I prefer Linux Boxes for web servers!
Cheers!

Resources