I am trying to set up the environment for VFP for an app I have tried SET DEFAULT & SET PATH TO I have also tried to use Environment Manager to all the directories of the prodject but when I run the program I have to use the locate dialog to find the files that the programe needs, main programme sets the environment I think, the code looks like this
CLOSE DATABASES ALL
CLOSE TABLE ALL
SET SYSMENU OFF
SET STATUS OFF
SET STATUS BAR OFF
_VFP.autoyield = .F.
IF FILE("c:\pb1\photobooth\photographer.exe")
SET DEFAULT TO c:\pb1\photobooth
ELSE
ON ERROR DO FORM FORMS\errorfrm WITH ERROR( ), MESSAGE( ), MESSAGE(1), PROGRAM( ), LINENO( )
ENDIF
SET PATH TO ..\CommandBars\Redistr,..\wwclient\,..\sfquery,..\classes,..\wwclient\classes, c:\sdt\sdt\source,c:\sdt\sdt\,..\xfrx,..\xfrx\xfrxlib
SET CLASSLIB TO (HOME()+"ffc\_reportlistener")
SET PROCEDURE TO PROGS\procfile ADDITIVE
SET PROCEDURE TO ..\xfrx\utilityreportlistener.prg ADDITIVE
SET PROCEDURE TO wwUtils ADDITIVE
SET PROCEDURE TO wwEval ADDITIVE
SET PROCEDURE TO CodeBlockClass ADDITIVE <-----
SET CLASSLIB TO wwIPStuff ADDITIVE
SET CLASSLIB TO wwXML ADDITIVE
SET PROCEDURE TO wwHTTP ADDITIVE
SET PROCEDURE TO WWPOP3 ADDITIVE
SET STATUS BAR ON
SET DATE BRITISH
SET DELETED ON
SET SAFETY OFF
SET MULTILOCKS ON
ON KEY LABEL SHIFT+F1 gl_diag=!gl_diag
I am looking for a way to run the programme with out errors so that I can find out why the app is not parsing all data to an XML file Tamar has provided a goog guide to debugging I just need to run the programme to the point the XML get generated. the errors start at the point indicated by the arrow
If the main program is setting the environment, you will likely be overwriting some of the settings by not using the ADDITIVE keyword. In your example, it looks like this is the case for SET PATH and SET CLASSLIB.
Example One - without ADDITIVE
*--- Main program
SET PATH TO "C:\VFP9"
*--- Debug setup
SET PATH TO "D:\Debug"
?set('Path')
Output: D:\Debug
Example Two - with ADDITIVE
*--- Main program
SET PATH TO "C:\VFP9"
*--- Debug setup
SET PATH TO "D:\Debug" ADDITIVE
?set('Path')
Output: D:\Debug;C:\VFP9
Related
I want to create a script that goes to a random url (english, french, and spanish, are just examples of url endings and not actual urls). There are probably better way to set variables, but I need it to be in this particular way because of the way the rest of the code is set up.
REM define list entries
set list[0]=english
set list[1]=french
set list[2]=spanish
REM create a random number, smaller than the list's length
set /a randomNum=(%RANDOM%*3/32768)
start "" http://youtube.com/%list[%randomNum%]%
This goes to youtube.com/randomNum, and not the value of the variables I set.
Any help getting it to go to youtube.com/english etc.?
I've been struggling to find a way to open a Read-only document in Normal/Edit mode instead of Reading mode with MS Word 2013. Word 2013 by default enables the start up option to "Open e-mail attachments and other uneditable files in reading view".
How would I go about disabling this option or changing the view from Reading to Normal/Edit view when the document is opened. (I need to keep the document as read-only as it might be accessed by multiple people at once)
Set objWord = CreateObject("Word.Application")
Set objDoc = objWord.Documents.Open(documentPath,,True)
objWord.ActiveWindow.ActivePane.View.Type = wdNormalView
I have tried to set the view mode using the above but received the an error code shown below. I looked at other variations of line 3 but can't get it to work. I'm still working my way around learning VBScript so I'm assuming i'm not doing this the right way.
Error: One of the values passed to this method or property is out of range
Code: 800A16D3
Source: Microsoft Word
Thanks.
You're using VBScript - it doesn't understand what wdNormalView means. This is an internal value for VBA. You need to find the actual value held for this constant and apply that instead. The constant is a WdViewType and the values are as follows:
Name Value Description
wdMasterView 5 A master view.
wdNormalView 1 A normal view.
wdOutlineView 2 An outline view.
wdPrintPreview 4 A print preview view.
wdPrintView 3 A print view.
wdReadingView 7 A reading view.
wdWebView 6 A Web view.
So the option you want to select is 1. Try the following code and see if this works:
Set objWord = CreateObject("Word.Application")
Set objDoc = objWord.Documents.Open(documentPath,,True)
objWord.ActiveWindow.ActivePane.View.Type = 1
I'm using VBScript to create a UAC prompt for a batch file. I don't know how to get the return value of the UAC prompt. For example if I try to UAC a file that doesn't exist I should get an error, right?
For example:
Dim rc
Set UAC = CreateObject("Shell.Application")
rc = UAC.ShellExecute("thisdoesntexist.exe", "", "", "runas", 1)
WScript.Echo rc
rc doesn't contain a code. Also, is there any way I can get the error code of whatever I'm executing? Is ShellExecute asynchronous in VBScript?
IShellDispatch2.ShellExecute method
Performs a specified operation on a specified file.
Syntax
IShellDispatch2.ShellExecute(sFile [, vArguments] [, vDirectory] [,
vOperation] [, vShow]) Parameters
sFile Required. String that contains the name of the file on which
ShellExecute will perform the action specified by vOperation.
vArguments Optional. Variant that contains the parameter values for
the operation.
vDirectory Optional. Variant that contains the fully qualified path of
the directory that contains the file specified by sFile. If this
parameter is not specified, the current working directory is used.
vOperation Optional. Variant that specifies the operation to be
performed. It should be set to one of the verb strings that is
supported by the file. For a discussion of verbs, see the Remarks
section. If this parameter is not specified, the default operation is
performed.
vShow Optional. Variant that recommends how the window that belongs to
the application that performs the operation should be displayed
initially. The application can ignore this recommendation. vShow can
take one of the following values. If this parameter is not specified,
the application uses its default value.0
Open the application with a hidden window.
1 Open the application with a normal window. If the window is
minimized or maximized, the system restores it to its original size
and position.
2 Open the application with a minimized window.
3 Open the application with a maximized window.
4 Open the application with its window at its most recent size and
position. The active window remains active.
5 Open the application with its window at its current size and
position.
7 Open the application with a minimized window. The active window
remains active.
10 Open the application with its window in the default state specified
by the application.
Return Value
No return value.
Remarks
This method is equivalent to launching one of the commands associated
with a file's shortcut menu. Each command is identified by a verb
string. The supported verbs vary from file to file. The most commonly
supported verb is "open", which is also usually the default verb.
Others might be supported only by certain types of files. For further
discussion of Shell verbs, see Launching Applications or Extending
Shortcut Menus.
This method is not currently available in Microsoft Visual Basic.
Examples
The following example uses ShellExecute to open Microsoft Notepad.
Proper usage is shown for Microsoft JScript and Visual Basic Scripting
Edition (VBScript).
<script language="VBScript">
function fnShellExecuteVB()
dim objShell
set objShell = CreateObject("Shell.Application")
objShell.ShellExecute "notepad.exe", "", "", "open", 1
set objShell = nothing
end function
</script>
Now all COM calls look like this HResult = methodcall(param1, param2, ..., paramn, OUTPARAM).
VB pretends it OUTPARAM = methodcall(param1, Param2, ..., paramn) with HResult appearing in the err.object.
So errors will still fire, it's just that it doesn't wait to find out.
I have a Setup and Deployment project in Visual Studio 2010.
I would like the installer to create two shortcuts to the executable of another project in my solution. One normal shortcut that simply runs the application using current credentials and another which has the Run as administrator flag set, thereby ensuring that the user is asked for credentials with administrative rights when clicking the shortcut.
Running the application with administrative rights enables certain features that are otherwise not available.
Setting this flag doesn't seem to be possible at first glance. Can this be done directly in Visual Studio? If not, are there any other options?
Edit: If not, is it possible to modify the shortcut programmatically using a custom installer class?
I know this is quite an old question, but I needed to find an answer and I thought I could help other searchers. I wrote a small function to perform this task in VBScript (pasted below). It is easily adapted to VB.net / VB6.
Return codes from function:
0 - success, changed the shortcut.
99 - shortcut flag already set to run as administrator.
114017 - file not found
114038 - Data file format not valid (specifically the file is way too small)
All other non-zero = unexpected errors.
As mentioned by Chada in a later post, this script will not work on msi Advertised shortcuts. If you use this method to manipulate the bits in the shortcut, it must be a standard, non-advertised shortcut.
References:
MS Shortcut LNK format: http://msdn.microsoft.com/en-us/library/dd871305
Some inspiration: Read and write binary file in VBscript
Please note that the function does not check for a valid LNK shortcut. In fact you can feed it ANY file and it will alter Hex byte 15h in the file to set bit 32 to on.
If copies the original shortcut to %TEMP% before amending it.
Daz.
'# D.Collins - 12:58 03/09/2012
'# Sets a shortcut to have the RunAs flag set. Drag an LNK file onto this script to test
Option Explicit
Dim oArgs, ret
Set oArgs = WScript.Arguments
If oArgs.Count > 0 Then
ret = fSetRunAsOnLNK(oArgs(0))
MsgBox "Done, return = " & ret
Else
MsgBox "No Args"
End If
Function fSetRunAsOnLNK(sInputLNK)
Dim fso, wshShell, oFile, iSize, aInput(), ts, i
Set fso = CreateObject("Scripting.FileSystemObject")
Set wshShell = CreateObject("WScript.Shell")
If Not fso.FileExists(sInputLNK) Then fSetRunAsOnLNK = 114017 : Exit Function
Set oFile = fso.GetFile(sInputLNK)
iSize = oFile.Size
ReDim aInput(iSize)
Set ts = oFile.OpenAsTextStream()
i = 0
Do While Not ts.AtEndOfStream
aInput(i) = ts.Read(1)
i = i + 1
Loop
ts.Close
If UBound(aInput) < 50 Then fSetRunAsOnLNK = 114038 : Exit Function
If (Asc(aInput(21)) And 32) = 0 Then
aInput(21) = Chr(Asc(aInput(21)) + 32)
Else
fSetRunAsOnLNK = 99 : Exit Function
End If
fso.CopyFile sInputLNK, wshShell.ExpandEnvironmentStrings("%temp%\" & oFile.Name & "." & Hour(Now()) & "-" & Minute(Now()) & "-" & Second(Now()))
On Error Resume Next
Set ts = fso.CreateTextFile(sInputLNK, True)
If Err.Number <> 0 Then fSetRunAsOnLNK = Err.number : Exit Function
ts.Write(Join(aInput, ""))
If Err.Number <> 0 Then fSetRunAsOnLNK = Err.number : Exit Function
ts.Close
fSetRunAsOnLNK = 0
End Function
This is largely due to the fact that Windows Installer uses 'Advertised shortcuts' for the Windows Installer packages.
There is no way inherently to disable this in Visual Studio, but it is possible to modify the MSI that is produced to make sure that it does not use advertised shortcuts (or uses only one). There are 2 ways of going about this:
If your application uses a single exe or two - Use ORCA to edit the MSI. Under the shortcuts table, change the Target Entry to "[TARGETDIR]\MyExeName.exe" - where MyExeName is the name of your exe - this ensures that that particular shortcut is not advertised.
Add DISABLEADVTSHORTCUTS=1 to the the property Table of the MSI using ORCA or a post build event (using the WiRunSQL.vbs script). If you need more info on this let me know. This disables all advertised shortcuts.
it may be better to use the first approach, create 2 shortcuts and modify only one in ORCA so that you can right click and run as admin.
Hope this helps
This is not supported by Windows Installer. Elevation is usually handled by the application through its manifest.
A solution is to create a wrapper (VBScript or EXE) which uses ShellExecute with runas verb to launch your application as an Administrator. Your shortcut can then point to this wrapper instead of the actual application.
Sorry for the confusion - I now understand what you are after.
There are indeed ways to set the shortcut flag but none that I know of straight in Visual Studio. I have found a number of functions written in C++ that set the SLDF_RUNAS_USER flag on a shortcut.
Some links to such functions include:
http://blogs.msdn.com/b/oldnewthing/archive/2007/12/19/6801084.aspx
http://social.msdn.microsoft.com/Forums/en-US/windowssecurity/thread/a55aa70e-ae4d-4bf6-b179-2e3df3668989/
Another interesting discussion on the same topic was carried out at NSIS forums, the thread may be of help. There is a function listed that can be built as well as mention of a registry location which stores such shortcut settings (this seems to be the easiest way to go, if it works) - I am unable to test the registry method at the moment, but can do a bit later to see if it works.
This thread can be found here: http://forums.winamp.com/showthread.php?t=278764
If you are quite keen to do this programatically, then maybe you could adapt one of the functions above to be run as a post-install task? This would set the flag of the shortcut after your install but this once again needs to be done on Non-Advertised shortcuts so the MSI would have to be fixed as I mentioned earlier.
I'll keep looking and test out the registry setting method to see if it works and report back.
Chada
I needed to make my application to be prompted for Administator's Rights when running from Start Menu or Program Files.
I achieved this behavior after setting in \bin\Debug\my_app.exe 'Run this program as administator' checkbox to true. ( located in Properties\Compatibility section ).
While installing project, this file was copied to the Program Files (and therefore the shortcut in the Start Menu) with needed behavior.
Thanks,
Pavlo
I have an application written in Excel plus a bunch of C++ / Python addins.
The location of the various config files used by the addins is determined at startup time by a number of environment variables. I'd like to debug a problem related to these environment variables by the most direct possible means: Can I simply type in an Excel formula which will cause an environment variable to display in the worksheet?
Let me give you an example:
I have an environment variable called "MYADDIN_XML_CONFIG" which contains the path to an XML file used by the MyAddin component. If this environment variable is set incorrectly then MyAddin will fail to run. I'd like to have a single simple function which takes the string "MYADDIN_XML_CONFIG" as an argument and returns the value of the env-var if it is set. If the environment variable is not set it should return a NONE or some kind of error code.
Can this be done?
FYI, MS Excel 2003 on Windows XP.
I don't know any built-in Excel formula that does this, but you can create a public function in a VBA module:
Public Function Env(Value As Variant) As String
Env = Environ(Value)
End Function
then use this as a user-defined formula in a worksheet, e.g.
=Env("COMPUTERNAME")
Use the VBA function Environ("MYADDIN_XML_CONFIG").
Unfortunately the accepted solution won't work if your environment variable changes its value (even if you reopen the Excel workbook, the value of the cell won't change). If you want to have it updated more often you should update cell's value on some event,
e.g. Worksheet_Activate (code should be placed in VBAProject->Microsoft Excel Objects->Sheet which should be observed):
Private Sub Worksheet_Activate()
Range("a1") = Environ("SOME_ENV_VARIABLE")
End Sub
or Workbook_Open (code should be placed in VBAProject->Microsoft Excel Objects->ThisWorkbook):
Private Sub Workbook_Open()
Range("a1") = Environ("SOME_ENV_VARIABLE")
End Sub