So what I am trying to accomplish is to always start. cscript.exe in native os version. SO I have access to the correct system files when my script runs and won't be redirected to the syswow64 regestry/files.
So according the msdn docs i can use the sysnative when running a 32bit application on a 64bit system to get the real system32 folder. But the script cant seam to find the the cscript.exe file. So the question is what am i doing wrong? I mostly a python guy so I might be making a stupid assumption.
This is compiled into a 32bit Service, so it could be deployed on any windows os(in theory)
Running VisualStudio 2010 if it matters
Or am I approaching the problem completely back to front?
Public Class Service1
Protected Overrides Sub OnStart(ByVal args() As String)
' Add code here to start your service. This method should set things
' in motion so your service can do its work.
'Prvents windows from redirecting us to the wow64 folder instead of system32.
' Don' run if settings file is gone
If My.Computer.FileSystem.FileExists("C:\Settings.vbs") Then
'If we are running in wow64(32bit windows files) mode switch to native 64 bit vbscript
If My.Computer.FileSystem.DirectoryExists("%systemroot%\sysÂnative") Then
Process.Start("%systemroot%\sysÂnative\cscript.exe", "C:\Main.vbs")
Else
Process.Start("%systemroot%\system32\cscript.exe", "C:\Main.vbs")
End If
End If
End Sub
Protected Overrides Sub OnStop()
' Add code here to perform any tear-down necessary to stop your service.
End Sub
End Class
Basicly to the question is How do I get cscript to run in 64bit mode rather than 32bit, so only really this line.
Process.Start("%systemroot%\system32\cscript.exe", "C:\Main.vbs")
That gets changed to C:\Windows\SysWOW64 when run a on a 64 bit system.
But stays on 32bit system it stays C:\Windows\system32.
I also tried this:http://msdn.microsoft.com/en-us/library/windows/desktop/aa365744%28v=vs.85%29.aspx
But I cant seam to figure out how to make it work. In a vb application
Answer over there
Option Infer On
Option Strict On
Imports System.IO Module Module1 Sub Main() Dim f As String = "" If IntPtr.Size = 4 Then f = Path.Combine(Environment.ExpandEnvironmentVariables("%windir%"), "sysnative") MsgBox("Running on X86") Else f = Environment.GetFolderPath(Environment.SpecialFolder.System) MsgBox("Running on X64") End If Dim wscript As String = Path.Combine(f, "wscript.exe") Dim psi = New ProcessStartInfo psi.FileName = wscript psi.Arguments = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), "CheckPlatform.vbs") Dim p As New Process p.StartInfo = psi p.Start() End Sub End Module
http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/48bc23b5-798f-4cea-ae33-060a0d66506b
Related
In my program i need to run exe file in process. I'm doing it with ProcessBuilder. When i'm putting to code only directory and exe name, process is running normally, but i want to put arguments. When i'm trying it i'm getting exception with Acces Denied message.
It's my code:
Process process = new ProcessBuilder("C:\\Directory", "file.exe", argument1).start();
What is wrong with it?
My earlier code, that worked but without arguments was:
String folder = "C:\\Directory";
String exe = "File.exe";
ProcessBuilder pb = new ProcessBuilder();
pb.command(folder + exe);
pb.start();
With this code i was able to see started process in ProcessManager.
Your code is trying to execute C:\\Directory which is not allowed.
The full path of the executable must be in the first argument to the constructor, so:
Process process = new ProcessBuilder("C:\\Directory\\file.exe", argument1).start();
This is assuming C:\Directory\file.exe is the program you are trying to run.
Update: In your original code you have:
String folder = "C:\\Directory";
String exe = "File.exe";
so 'folder + exe' is C:\DirectoryFile.exe so you the equivalent code is:
Process process = new ProcessBuilder("C:\\DirectoryFile.exe", argument1).start();
I created a small IronPython Script to list all Installed Software from a Windows PC.
import _winreg
def subkeys(key):
i = 0
while True:
try:
subkey = _winreg.EnumKey(key, i)
yield subkey
i+=1
except:
break
def traverse_registry_tree(key=_winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\"), tabs=0):
output = []
for k in subkeys(key):
meep = _winreg.OpenKey(key,k)
if _winreg.QueryValueEx(meep,"DisplayName")[0] == None:
string = str(k)
else:
string = str(_winreg.QueryValueEx(meep,"DisplayName")[0])
output.append('\t'*tabs + string)
traverse_registry_tree(k, tabs+1)
output.sort()
return output
output_file = open("output.txt",'w')
for line in traverse_registry_tree():
tmp = line + '\n'
output_file.write(tmp)
output_file.close()
After compling it with the following Options:
/main:wmi_test.py /out:test /embed /standalone /target:winexe
I generated the output.txt from the executable and the output.txt from the script. There is however a big difference between them:
http://www.diffchecker.com/wfbh79af
Here is a screenshot from "Uninstall Software" in the Windows Configuration Center:
http://jschpp.de/software.png
Could you help me to understand why there is such a big discrepancy.
I am using IronPython 2.7 on Windows 7 Professional x64
When you say script, I assume you mean using ipy.exe wmi_test.py. The ipy.exe shipped with ironpython is a 32-bit executable (for various reasons); the executables built with pyc.py are AnyCPU, which means 64-bit for you. Windows has different registries for 32 and 64 bit programs.
An easy way to check that this is the case is to run the script with ipy64.exe instead and compare the results.
This question already has an answer here:
While Running the vba script i am getting error Microsoft VBScript runtime error: object required : 'DoCmd'
(1 answer)
Closed 8 years ago.
Hi Any one please help me..
while running the vba script i am getting error--object DoCmd need to create.
My script is given below..
ExecuteInsert
Sub ExecuteInsert()
Dim sheetPath
Dim dbs, DbFullName, acc
Set acc = CreateObject("Access.Application")
DbFullName = "D:\G\Diamond\FINAL MS-Access\Demo\MS-Access project.accdb"
Set dbs = acc.DBEngine.OpenDatabase(DbFullName, False, False)
dbs.Execute "Delete from TempRoadMap"
sheetPath = "C:\Users\270784\Desktop\CSPRV scheduled work - 2014 through 1-26-14.xlsx"
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel97, "TempRoadMap", sheetPath, True
MsgBox "Imported Sheet1 from " & sheetPath & " Successfully!"
dbs.Execute "Delete from RoadMap"
dbs.Execute "INSERT INTO [RoadMap] ( Release_Name,SPRF,SPRF_CC,Estimate_Type,PV_Work_ID,SPRF_Name,Estimate_Name,Project_Phase,CSPRV_Status,Scheduling_Status,Impact_Type,Onshore_Staffing_Restriction,Applications,Total_Appl_Estimate,Total_CQA_Estimate,Estimate_Total,Requested_Release,Item_Type,Path) SELECT [TempRoadMap.Release Name], [TempRoadMap.SPRF], [TempRoadMap.Estimate (SPRF-CC)],[TempRoadMap.Estimate Type],[TempRoadMap.PV Work ID],[TempRoadMap.SPRF Name],[TempRoadMap.Estimate Name],[TempRoadMap.Project Phase],[TempRoadMap.CSPRV Status],[TempRoadMap.Scheduling Status],[TempRoadMap.Impact Type],[TempRoadMap.Onshore Staffing Restriction],[TempRoadMap.Applications],[TempRoadMap.Total Appl Estimate],[TempRoadMap.Total CQA Estimate],[TempRoadMap.Estimate Total],[TempRoadMap.Requested Release],[TempRoadMap.Item Type],[TempRoadMap.Path] FROM [TempRoadMap] "
dbs.Close
MsgBox "Done"
End Sub
Assuming that by "...through cmd prompt..." you mean to imply that you are running this script as part of a VBScript file, here are the changes you would want to make:
DoCmd is a child of an Access.Application, and it can only be referenced globally in the scope of an Access database. To reference it in VBScript, you must explicitly use an Access.Application instance, which you have as variable acc. Modify the beginning of the DoCmd line like so:
acc.DoCmd.TransferSpreadsheet
VBScript won't recognize Access constants like acImport or acSpreadsheetTypeExcel97, so you will have to replace them with their actual values. A quick look through msdn reveals that acImport is 0 and acSpreadsheetTypeExcel97 doesn't exist, but acSpreadsheetTypeExcel8 (Excel 97 format) is 8. So now the DoCmd line looks like:
acc.DoCmd.TransferSpreadsheet 0, 8, "TempRoadMap", sheetPath, True
VBScript does not have MsgBox - this is only available through VBA. Instead, you can use Wscript.Echo. For example, the last line would be: WScript.Echo "Done"
If you still have issues after making those changes, please let me know with a comment below.
VBScript certainly does have msgbox and echo is not part of vbscript but of Windows Scripting Host.
I want my program to launch another desktop application.
Tried shell execute (open appname) but it does not work.
Is there another way ?
Thank you in advance.
Another possibility is use the standard Xojo FolderItem and use the Launch method.
Dim f as folderitem = specialfolder.applications.child("AppName")
if f <> nil and f.exists then
f.launch
end
Reference Documentation:
http://docs.xojo.com/index.php/SpecialFolder
http://docs.xojo.com/index.php/FolderItem.Launch
dim s as new Shell
s.Execute("open -a ""Finder""")
' Check error code and do something about it...
if s.ErrorCode <> 0 then
MsgBox("Error code: " + Str(s.ErrorCode) + EndOfLine + "Output: " + s.Result)
end if
Change "Finder" to whichever application you need, or build a string and pass that to s.Execute(). Be sure to include escaped quotes, especially if the application has spaces in its name.
I'm not familiar with Xojo, however "launching" an application on OS X is complicated. There are many things you need to consider, especially if it's already running.
I recommend you look into two possible options, either use Xojo's ability to launch call native C code to run one of the three -[NSWorkspace launchApplication...] methods: https://developer.apple.com/library/mac/documentation/cocoa/reference/applicationkit/classes/NSWorkspace_Class/Reference/Reference.html#//apple_ref/doc/uid/20000391-SW23
Alternatively, use Apple's open command line tool:
/usr/bin/open -a "App Name"
/usr/bin/open -a "/Applications/App Name.app"
I was playing with some ruby the other day and I wrote the following code
File.open(my_file, "w+") do | fh |
begin
fh.readonly = true <--------Exception thrown here
ensure
fh.close
end
end
this does not work as it throws EACCES because the file is readonly, if I change the open flag to "r" this works just fine. To me this is counter intuitive because I thought opening it with "r" meant i'd only be able to read the file, not change attributes.
I am using win32-file (0.6.6) with ruby 1.8.7 (not upgradable for current project), is this normal behaviour a quirk of the win-32 file gem or just a bug that I am able to code around.
In order to set the readonly bit to true I must open with w+ which seems much more sensible
A bit more info is that this test was performed on Windows Server 2003 64-bit, just in case that makes a diff.
Try opening the file with read and write permissions.
File.open(my_file, "rw+") do | fh |
begin
fh.readonly = true
ensure
fh.close
end
end
I eventually found out what this was, there was another process locking the directory with an exclusive lock on the filesystem, It didn't show up with processexplorer but i noticed in my log something logging that directory, I stopped the service and bam it worked.