In my csproj file, I have a different build path.
<BaseIntermediateOutputPath>C:\Temp\Build\MyProject</BaseIntermediateOutputPath>
When in the prebuild and post build events, I have access to certain macro variables.
$(OutDir)
$(ProjectName)
$(ProjectPath)
$(SolutionDir)
Can I use those variables within my csproj?
For example, I tried the following without success.
<BaseIntermediateOutputPath>C:\Temp\Build\$(ProjectName)</BaseIntermediateOutputPath>
I had a similar requirement and using $(MSBuildProjectName) did the job for me.
<PropertyGroup>
<ProjectView>ProjectFiles</ProjectView>
<BaseIntermediateOutputPath>R:\$(MSBuildProjectName)\obj\</BaseIntermediateOutputPath>
</PropertyGroup>
Here R: is my RAMDISK drive letter.
For others who may also face issues in setting up the RAMDISK drive letter correctly, I used a simple VBS script
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colVolumes = objWMIService.ExecQuery _
("Select * from Win32_Volume") Where Label = 'RAMDISK'")
For Each objVolume in colVolumes
objVolume.DriveLetter = "R:"
objVolume.Put_
Next
This ensures that any drive loaded with the label RAMDISK is set to R: drive instead of the default drive that appears. While this is not part of your Q, I am sure that this will be handy to others who have similar requirements of using the RAMDISK for their obj files and find the case of changing drive letters in vbproj/csproj files cumbersome.
References:
Reserved properties: http://msdn.microsoft.com/en-us/library/ms164309%28loband%29.aspx
Changing drive letters: http://www.activexperts.com/activmonitor/windowsmanagement/adminscripts/disk/drives/
Related
Need assistance in creating vbs. I have exe which can be executed from anywhere. so i need to get the exe location and add to registry entry.
Ex: location of exe : c:\abc\execute.exe
registry location : HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Compatibility Assistant\Persisted
Add key as c:\abc\execute.exe dword=1
thanks in advance
You could use something like this, if I am understanding your question correctly.
To call this script, you would simply go to the Start menu, and type into the search box (or run box):
cscript {path-to-your-script\scriptname.vbs} /filepath:"C:\abc\execute.exe"
You would need to replace {path-to-your-script\scriptname.vbs} with the full path and filename of the script example provided below. Remember to save the code snippet with a .vbs extension.
This vbs snippet will silently add C:\abc\execute.exe with a dword value of 1 under the key HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Compatibility Assistant\Persisted if the registry path exists and the executing account has sufficient permissions to do so.
NOTE: This script snippet will not work on older versions of Windows as wscript.arguments.Named.Item is not supported.
' cscript <scriptname.vbs> /filepath:"C:\abc\execute.exe"
Const HKEY_CURRENT_USER = &H80000001
filePath = wscript.arguments.Named.Item("filepath")
Value = 1
strComputer = "."
Set objRegistry = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
strKeyPath = "Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Compatibility Assistant\Persisted"
if filePath <> "" then
objRegistry.SetDWORDValue HKEY_CURRENT_USER, strKeyPath, filepath, Value
end if
Hope that helps.
I need to be able to often renaming multiple folders in ASP. None of the methods that I've found are working for me. Here is the current method that I am trying-
Set FS = CreateObject("Scripting.FileSystemObject")
FS.MoveFolder "/images/715", "/images/V14"
This, as well as others that I've tried, always gives me a "path not found" error. I know that the directory that the script is in has these folders in it because I've been renaming them manually. Does the script need to know the full path? What if I don't know what the full path may be?
Update:
The script runs in a directory named "/ifp". I also tried this, with and without the "/ifp" and both forward and back slashes, and it also gave path not found. Once this works on my testing server I send it to the guy with the production server so I can't use any static directory names other than the "/images/????"
Dim sCurPath
sCurPath = CreateObject("Scripting.FileSystemObject").GetAbsolutePathName(".")
FS.MoveFolder sCurPath & "\ifp\images\715", sCurPath & "\ifp\images\V14"
Use absolute paths (C:\images\715). It would look like this:
Set FS = CreateObject("Scripting.FileSystemObject")
FS.MoveFolder "C:\images\715", "C:\images\V14"
If you are using a -nix system then keep in mind that the first / is the root directory - ensure you do indeed have an images folder in the root directory path.
Also note that in order to rename the folder there cannot be trailing \'s after the folder names and the script must be run on the local machine.
If you keep getting path errors, you're passing it incorrectly somehow. Build in some error checking to see what is going wrong:
Dim tmpPath = "\ifp\images\715"
Dim newPath = "\ifp\images\V14"
If FS.FolderExists(sCurPath & tmpPath) Then
Response.Write("The folder exists.")
FS.MoveFolder sCurPath & tmpPath, sCurPath & newPath
Else
Response.Write("The folder " & sCurPath & tmpPath & " does not exist.")
End If
I am new to VB scripting and need help on a program to do the following, Can someone please help me out. It would be great if this whole program can be embedded into one vbscript.
Write a script to check
if a process is running or not( example notepad++.exe),
if its running then dont do anything.
If the process is not running, check if a directory is present or not under C:\Program Files(x86)
Say if the directory is not there then copy the .exe file from a network shared location onto a local drive and
then perform the command line installation in silent mode.(example> notepad++.exe -ms)
You can use this example. You need to put an if check and compare with objItem.Name = "notepad.exe" and do whatever you wish to do:
sComputerName = "."
Set objWMIService = GetObject("winmgmts:\\" & sComputerName & "\root\cimv2")
sQuery = "SELECT * FROM Win32_Process"
Set objItems = objWMIService.ExecQuery(sQuery)
'iterate all item(s)
For Each objItem In objItems
WScript.Echo "Process [Name:" & objItem.Name & "]"
Next
Also note you can use WHERE statement in query:
SELECT * FROM Win32_Process WHERE Name LIKE '%notepad%'
Here you can find names of columns for query:
I have few remote servers for which i need to create shortcuts and put those shortcuts in a folder.And place it in users machine, so that when user clicks on the shortcut,User will get the explorer of D:\ drive on the remote server. Please help in this regard
Here's some example vbscript that'll do the trick I think. (credit where credit is due)
Set oShell = CreateObject("WScript.Shell")
sAllUsersDesktopPath = oShell.SpecialFolders("AllUsersDesktop")
sWinSysDir = oShell.ExpandEnvironmentStrings("%SystemRoot%\System32")
Set oShortCut = oShell.CreateShortcut( _
sAllUsersDesktopPath & "\D Drive on gibson.lnk")
oShortCut.TargetPath = sWinSysDir & "\Explorer.exe"
oShortCut.Arguments = "\\servername\d$"
oShortCut.IconLocation = sWinSysDir & "\Shell32.dll,10"
oShortCut.Save
Change the oShortCut.Arguments value as needed to point to the appropriate share on your servers, and change the "D drive on gibson" name as necessary. Save this to a .vbs file and execute it with cscript or wscript.
Or you can try using the freeware shortcut.exe from Optimum X.
I'm looking for something similar to this question. However, I am looking specifically to dynamically find the location of the system's temp folder (i.e. the temp folder used by services.)
Is this possible?
Thanks,
Here you go (in VBS)
Set environmentVars = WScript.CreateObject("WScript.Shell").Environment("Process")
tempFolder = environmentVars("TEMP")
msgbox(tempFolder)
I'm not sure if your system will have an environment variable called "TEMP", so go to the command line and type
set
You'll get a list of environment vars, and their values. Pick the one that has your temp folder in it.
Set objShell = CreateObject("WScript.Shell")
Set colEnvironment = objShell.Environment("PROCESS")
objPath = colEnvironment("temp")
WScript.Echo objPath
In that case
Set objShell = CreateObject("WScript.Shell")
Set colEnvironment = objShell.Environment("PROCESS")
objPath = colEnvironment("windir")
WScript.Echo objPath & "\temp"
hope this will help
After researching a little into this, I believe there is no way to use environment variables to capture the location of another user's %TEMP% folder (in this case the System user).
The SYSTEM environment variables is stored in registry key: HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session Manager\Environment
The environment variables for users is stored in registry keys: HKEY_USERS[user SID]\Environment
In order to get the value of any environment variable (in particular TEMP), need to check the presence of this variable in the branch for specified the user. If it is there, then you can use it. If it is not there, then you need to take a value from the system registry branch.
In C#, its...
System.Collections.IDictionary Vars = System.Environment.GetEnvironmentVariables();
String TempPath = Vars["TEMP"];
You get an entire array of elements... Path, Temp, SessionName, PathExt, UserDomain, SystemDrive, WinDir, etc...
Maybe this may be of some use: System.IO.Path.GetTempPath()