I am a Java programmer, and I do not know anything about VBScript. I needed a way to modify the target path of a certain shortcut, and I according to my research, only VBScript can help me. I tried it, but there were many errors.
I tried to resolve them by a butt ton of googling, but I think there is some other problem.
Here is the code:
Set sh = CreateObject("WScript.Shell")
Set shortcut = sh.CreateShortcut("C:\Users\pedne\Desktop\Zoom.lnk")
shortcut.TargetPath = "C:\Users\pedne\AppData\Roaming\Zoom\bin\Zoom.exe ""--url=zoommtg\://zoom.us/join?action=join&confno=955 1234 1234&pwd=12345"""
shortcut.Save
I do not know whether I need any prerequisites or external libraries for writing VBScript code, and I wrote it on notepad.I would also like to know whether there is any 100% Java or any other workaround to this. (Totally up to you)
Please excuse me if I do not understand anything about your answers as I copied the code from Change a shortcut's target from command prompt
The last error I got was at Line 3 char 1, Invalid procedure or call
Do not append the arguments to the target path. Use the Arguments property instead:
shortcut.TargetPath = "C:\Users\pedne\AppData\Roaming\Zoom\bin\Zoom.exe"
shortcut.Arguments = "--url=zoommtg\://zoom.us/join?action=join&confno=955 1234 1234&pwd=12345"
shortcut.Save
Related
Hello to whoever reading this.
This is not actually a question. It's a problem i faced and i was trying to find solution here in stackoverflow. But i couldn't. [Chances are it may be duplicate in the eyes of experts]. Anyway thought i'll share the solution which is working for me.
The Problem
I work on Windows CE panels so in some scenario I need to read batch script variable in CMakeLists.txt to do some filtering based on whether it's Windows x86 or Windows CE. How to do that ?
Could be the same as This but for me export didn't work. So the whole picture.
Later checked export is in bash. In batch set will work
The Answer which is working for me. [There are chance that other solution also exists but this worked for me]. Ok here it goes.
In batch file
set "PANEL_TYPE=WINCE"
In CMakeLists.txt
if( $ENV{PANEL_TYPE} STREQUAL "WINCE")
message(STATUS "Print Message = " $ENV{PANEL_TYPE})
set(THE STUFF)
else()
message(STATUS "Other Message = " $ENV{PANEL_TYPE})
endif()
That's it. It seems simple to me and it worked :)
Right now I have a batch file that sets the PATH variable to all of the required directories.(there is actually a bunch more required directories, i just took them out so the code snippet would not be too long)
#echo off
set PATH=D:/src/trunk/build/bin;D:/src/trunk/build/bin/CoreTools;D:/src/trunk/build/bin/Plugins/Extensions;D:/src/trunk/build/bin/Plugins/CustomUI
set DEBRIEF_INSTALL_DIR=D:/src/trunk/DebriefSuite/D3D_Installation
set READERS=D:/src/trunk/build/bin/CoreTools/Readers
set BINARY_DIR=D:/src/trunk/build
cd D:/src/trunk/build/bin
start PROGRAM.exe --ConfigFile="D:/src/trunk/DebriefSuite/Installation/config/Projects/config.xml" ^
--Mode-File="D:/src/trunk/DebriefSuite/Installation/config/Projects/Common/anotherconfig.xml" ^
--Env:Bin="D:/src/trunk/build/bin"
cd D:/src/trunk
It works fine, but all of the directories are hard-coded. This needs to be able to work for other computers that might have their root directory in a different location. I need to be able to pass in a root directory (something like "D:\different_root_location") and substitute it in to each place in this code that currently says "D:\src\trunk". The problem is, i am not sure what the syntax would be for something like this. I am new to writing batch files. I tried doing something like
SET ROOTDIR=%1 .....
And then
set PATH=%ROOTDIR%/build/bin;%ROOTDIR%/build/bin/CoreTools;%ROOTDIR%/build/bin/Plugins/Extensions;%ROOTDIR%/build/bin/Plugins/CustomUI ..........
start PROGRAM.exe --ConfigFile="%ROOTDIR%/DebriefSuite/Installation/config/Projects/config.xml" ^
but it did not work. I'm not really sure how to make this work! Also, any links to good sources of information about writing batch files in general would be extremely helpful since i am starting out!
Change your line so it includes the original path as well.
From this:
set PATH=D:/src/trunk/build/bin...
to this: (and Windows uses \ and not / even though it works in some cases)
set PATH=%path%;D:\src\trunk\build\bin....
I have attempted to follow the instructions on this post but I am falling short of understanding how some of the posters instructions work.
I want to be able to package the app with a prewritten bash script and then execute it, but don't follow from Step 4 onwards.
Post writes:
4. Also in your AppleScriptObjC script, add the following where appropriate:
property pathToResources : "NSString" -- works if added before script command
5. Where appropriate, also add the following in your AppleScriptObjC script:
set yourScript to pathToResources & "/yourScriptFile.sh"
-- gives the complete unix path
-- if needed, you can convert this to the Apple style path:
set yourScriptPath to (((yourScript as text) as POSIX file) as alias)`
6. As an aside, you could then open the file for read using
tell application "Finder"
open yourScriptPath
end tell
Questions:
Where do I add the line:
property pathToResources : "NSString"
Do I add which of the following, and where?
set yourScript to pathToResources & "/yourScriptFile.sh"
OR
set yourScriptPath to (((yourScript as text) as POSIX file) as alias)
How is it possible to execute the script itself? The mention As an aside, you could then open the file for read using only covers the Apple style path, it does not cover using the aforementioned style.
Can anyone shed a bit more light on this for me, or post a static copy of a AppDelegate.applescript file that shows how the original poster required the base code to be used? I have tried his method and looked across the internet for the past 3 weeks to no avail. I don't want to have to convert all my code for specific tools from bash scripts into AppleScript, as this would take a lot of work.
I only need to know how to reference to the script file (for example myBashScript.sh) in my app, which would reside in the application and be included by Xcode at time of compilation.
I think you should use the command path to resource <specifiedResource>.
See Standard Additions, path to resource.
You could set it by set myVariableName to path to resource "myBashScript.sh" or just use the command instead of your property so it points always to the right place (a user could move your app while running... lol).
ADDITION:
I did it that way in my AppleScript-Application:
on run_scriptfile(this_scriptfile)
try
set the script_file to path to resource this_scriptfile
return (run script script_file)
end try
return false
end run_scriptfile
Whenever I want to run a script that is bundled within my app I do this:
if my run_scriptfile("TestScript.scpt") is false then error number -128
run_scriptfile(this_scriptfile) returns true when everything worked.
I ended up bringing all the information together and now have a solution.
This takes into consideration the following facts:
firstScript = variable name that points to a script called scriptNumberOne.sh
scriptNumberOne.sh = the script that I have embedded into my application to run
ButtonHandlerRunScript_ = the name of the Received Action in Xcode
pathToResources = variable that points to the internal Resources folder of my application, regardless of it's current location
Using this information, below is a copy of a vanilla AppDelegate.applescript in my AppleScriptObjC Xcode project:
script AppDelegate
property parent : class "NSObject"
property pathToResources : "NSString"
on applicationWillFinishLaunching_(aNotification)
set pathToResources to (current application's class "NSBundle"'s mainBundle()'s resourcePath()) as string
end applicationWillFinishLaunching_
on ButtonHandlerRunScript_(sender)
set firstScript to pathToResources & "/scriptNumberOne.sh"
do shell script firstScript
end ButtonHandlerRunScript_
on applicationShouldTerminate_(sender)
-- Insert code here to do any housekeeping before your application quits
return current application's NSTerminateNow
end applicationShouldTerminate_
end script
I'm not understanding this behavior. Maybe someone can explain to me why my current working directory is not what I expect.
On my desktop, I have a folder called STKGui:
C:\Documents and Settings\Lauren\Desktop\STKGui
Located in that directory are the following files: gui.html, style.css, save.html, load.html Within STKGui there are also the following directories: Images, Scripts, and SaveData. Scripts contains various .vbs files, including gui.vbs.
I start with gui.html. I click a button which takes me to load.html. load.html uses scripts from Scripts\gui.vbs. One of the functions loads a database, and to do so I provide the location of the database: C:\Documents and Settings\Lauren\Desktop\STKGui\SaveData\SaveData.accdb Of course I want to use a relative file path instead of a fixed path. My initial attempt to load the database failed; it was trying to load from C:\Documents and Settings\Lauren\Desktop\SaveData\SaveData.accdb. So to troubleshoot I printed out the current working directory; much to my chagrin it was C:\Documents and Settings\Lauren\Desktop
I don't understand why my desktop is my current working directory. Shouldn't it be where the file is running from? I figured it would be either C:\Documents and Settings\Lauren\Desktop\STKGui (the location of load.html) OR C:\Documents and Settings\Lauren\Desktop\STKGui\Scripts (the location of gui.vbs which contains the function that's trying to load the database/printing debug messages of the current working directory).
Can someone explain why the current working directory is what it is, or better yet tell me how to get what I really want, which is the location of the files executing? (I don't care if it's the main STKGui folder or the scripts folder--as long as it's within the application's directory structure I can work with it!)
EDIT (7/14/10 4:02 pm EDT):
Various attempts at printing the current working directory or grabbing files based on what I -thought- was the relative path from my executing script have resulted in my desktop's path instead of the path of the executed script. I stumbled across this link: http://leereid.wordpress.com/2008/03/19/vbscript-current-directory-or-folder/ but none of the solutions are working for me, as I get run-time errors regarding the Wscript object. So while I don't know if any of the solutions on the aforementioned link will produce different results, if someone can help me get at least one of them working so I can find out that may be a step in the right direction.
One of the solutions, reproduced below:
Set oShell = CreateObject("WScript.Shell")
Set ofso = CreateObject("Scripting.FileSystemObject")
oShell.CurrentDirectory = ofso.GetParentFolderName(Wscript.ScriptFullName)
produces the following error:
Object required: 'Wscript' line: 659 char: 1
with line 659 being:
oShell.CurrentDirectory = ofso.GetParentFolderName(Wscript.ScriptFullName)
For Server-Side:
You should be using Server.MapPath() to get your "working directory". For instance, if you want to get the path to your database file in C:\Documents and Settings\Lauren\Desktop\STKGui\SaveData\SaveData.accdb, your app root being C:\Documents and Settings\Lauren\Desktop\STKGui, you would use Server.MapPath("SaveData\SaveData.accdb").
For Client-Side:
Upon closer examination and digging up some memories, I realized that MapPath is only available from the Server class. Instead, you need to create a file system object like this:
''get fs object
Set objFSO = CreateObject("Scripting.FileSystemObject")
''get actual file using path relative to calling vbs file
Set objFile = objFSO.GetFile("SaveData\SaveData.accdb")
''get path to the database
set sPathToDatabase = objFSO.GetAbsolutePathName(objFile)
In case it helps, here is a great resource for working with the file system in vbScript: http://www.activexperts.com/activmonitor/windowsmanagement/adminscripts/filesfolders/files/
This solution was NOT ideal, but what I ended up doing was parsing the url in my browser to get the directory.
guiPath = Mid(location.PathName, 2, len(location.PathName))
Set regExp = New RegExp
regExp.IgnoreCase = False
regExp.Global = True
regExp.Pattern = ".*/"
Set matchCollection = regExp.Execute(guiPath)
Set match = matchCollection(0)
guiPath = match.value
regExp.Pattern = "%20"
guiPath = regExp.Replace(guiPath, " ")
systemsDBPath = guiPath & "SaveData\SaveData.accdb"
Like I said, less than ideal. May not even work once I'm working with the application this will be running in. But I couldn't find a better way.
I'm trying to convert a program from Linux to use on Windows, and it calls test -f, or test -d on Linux. I need it to do the same thing on Windows. Is there a built-in command, or another program I can use to do the same thing?
I'm programming using FreeBASIC (horrible, but it's what I got).
EDIT: An external program is the best option here. I've looked at the API, and it's not good.
Never heard of FreeBasic before but looking at the help there's a DIR command that supports using fbDirectory as one of the attribute patterns to filter for.
And looking slightly further down on that page I just saw that they have a sample for checking if the objects found are files or directories. Just look here, look at the second example on that page.
Not sure what exactly those test commands do, but if you want to test if a specific object is a directory you should be able to call Dir("exactname", fbDirectory, something) I'd thought. And then you could test for a file by putting a Not in somewhere (assuming that FreeBasic supports that).
Edit: To make your own tool, here's a sample that shows a tiny C++ app that could easily be changed to look for directories or not. Look for the FindFirstFile in the sample and shortly after that it checks if it's readonly, which could be changed for FILE_ATTRIBUTE_DIRECTORY.
http://unxutils.sourceforge.net/
you can use test.exe just like under linux
Not sure about FreeBASIC, have you looked into vbscript? You could use the FileSystemObject
Dim fso, msg
Set fso = CreateObject("Scripting.FileSystemObject")
If (fso.FolderExists(fldr)) Then
'Do Something here
Else
'Do Something
End If
If (fso.FileExists(filespec)) Then
'Do Something here
Else
'Do Something
End If
You can also use Kiwi for FreeBasic in order to check if a path leads to a file or directory. You can find Kiwi on Github (https://github.com/nsiatras/kiwi)
#include once "kiwi\kiwi.bi"
#include once "kiwi\io.bi"
' Declare a new file
Dim myFile as File = File("C:\Users\nsiat\Desktop\Test.txt")
' Check if file exists, is a File or is a Directory
print "File exists: " & myFile.exists()
print "Is file: " & myFile.isFile()
print "Is Directory: " & myFile.isDirectory()