Showing posts with label Environment Variables. Show all posts
Showing posts with label Environment Variables. Show all posts

Wednesday, April 04, 2012

VBScript to copy file and Powershell Script to copy file

VBScript to copy file:

dim filesys, oShell
Set filesys = CreateObject("Scripting.FileSystemObject")
Set oShell = CreateObject("WScript.Shell")
sup = oShell.ExpandEnvironmentStrings ("%APPDATA%")
des = oShell.ExpandEnvironmentStrings ("%ProgramFiles(x86)%")
destfile= sup & "\AR System\HOME\AR"
sourcefile= des & "\AR System\User\AR"
If filesys.FileExists(sourcefile) Then
   filesys.CopyFile sourcefile, destfile
End If


Powershell Script to copy file:

$SourceFile = "c:\foo\Test.txt"; 
$NewFile    = "c:\foo\Test2.txt"; 
 
# Now - check to see if $Sourcefile exists, and if so, 
# copy it to $newfile  
if ([System.IO.File]::Exists($SourceFile))  { 
   [System.IO.File]::Copy($SourceFile, $NewFile) 
   "Source File ($SourceFile) copied to ($newFile)" 

else { 
"Source file ($Sourcefile) does not exist." 
}

Thursday, August 11, 2011

Installing executable from remote location by suppressing the Open File Prompt

Many times while running a script/application exe from a network we get an error that the application is not from a trusted source and if we want to install the particular application or not.
This error comes because the source is not digitally signed and the Operating System prompts to ask from user if it is a known source to user or if something malicious is being run from network. This is just to protect the end users from the malicious software or Virus attack.

Technically,

This behavior was introduced in Windows XP SP2 because of the addition of the Attachment Execution Services (AES). Every program that is run by using the ShellExecute() API passes through AES. AES considers the downloaded update file to be from the Internet Zone. Therefore, AESdisplays the Open File - Security Warning dialog box. AES examines the file to see whether the file has a file stream of the type Zone.Identifier. Then AES determines what zone the file is from and what level of protection to apply when the file is run.

You can use the below code to suppress this message for your application to work fine.


set oShell= CreateObject("Wscript.Shell")

set oEnv = oShell.Environment("PROCESS")

oEnv("SEE_MASK_NOZONECHECKS") = 1

<Your Code here>

oEnv.Remove("SEE_MASK_NOZONECHECKS")


Please note that you should not set this as a permanent environment variable as it will disable all Zone Checking and it is not recommended.

Monday, May 14, 2007

Modify the System and User Paths

SUMMARY: The PATHMAN DOS command can make it easier to modify the system and user paths used by Windows XP.

If you are in the C:\TEMP directory and type in NETSTAT at a command prompt to view active connection statistics, Windows will most likely not find "netstat.exe" in the C:\TEMP directory.

However, the C:\WINDOWS\SYSTEM32 directory is in what's called the path, or a list of directories Windows uses if it can't find an executable in the current directory. Since C:\WINDOWS\SYSTEM32 contains the file "netstat.exe", Windows will run the command from there.

By using the SET command with the PATH environment variable, you can modify Windows XP's path. However, doing so can be messy and error-prone.

If you frequently need to modify the PATH, the Windows 2003 Resource Kit comes built-in with a command called PATHMAN, or Path Manager, that lets you cleanly modify the system and user paths.

To use this command, you'll need to first
download and install the Windows 2003 Resource Kit.

Then you can run pathman.exe and use one of the following options:

/as PATHAdds a semicolon-separated PATH to the system path
/au PATHAdds a semicolon-separated PATH to the user path
/rs PATHRemoves a semicolon-separated PATH from the system path
/ru PATHRemoves a semicolon-separated PATH from the user pathExamples:C:\>pathman /as c:\morecommands
This adds the directory "c:\morecommands" to the system path.
After restarting the current command prompt or opening a new command prompt, any batch files or executables located in the "c:\morecommands" directory are now executable from anywhere on your system.
Type the following command in a new DOS window to see your modified PATH environment variable:
C:\>set path
Now, to remove the directory from the path:C:\>pathman
/rs c:\morecommands
This removes the directory "c:\morecommands" from the system path.
After restarting the current command prompt or opening a new command prompt, any batch files or executables located in the "c:\morecommands" directory will only be executable from within the "c:\morecommands" directory.
Type the following command in a new DOS window to see your modified PATH environment variable:
C:\>set path


Source:
http://malektips.com/xp_dos_0017.html