User defined database location - windows-7

My application, originally created in win XP using vb6, stores program specific values in the registry. One of those values is where the database the program uses is located. The user can put it where ever they like and the program starts it prime the db location screen with the values last saved from the registry. This form uses the DriveListBox, DirListBox, and the FileListBox components. When running this application on Win 7, i am getting an error trying to set the dir list to the value stored in the registry which is a network drive. This all work fine if the drive the db is stored on is local.
The code is:
On Error GoTo HandleError
dbLocation = GetSetting(App.Title, "Settings", "DBLocation", dbserver)
If dbLocation = dbserver Then
Dir1.Path = GetSetting(App.Title, "Database", "ServerDBPath", "C:\") <----- fails
Else
Dir1.Path = GetSetting(App.Title, "Database", "LocalDBPath", "C:\")
End If
Drive1.Drive = Dir1.Path
Exit Sub
HandleError:
MsgBox "Error connecting to the network. Check network connections and try again.", vbOKOnly, "Connection error"
Drive1.Drive = "C:\"
I am suspecting the problem is with the directory list box. If i remove my error handling, the error thrown is "Device Unavailabe"
Any ideas on what happening? Are the components I am using not valid for win 7? For this application, the database has to be on a network drive so it is accessable from several PCs running the program. All of the PCs are running on Windows 7.

The drive, directory and file controls that come with VB6 are hopelessly out of date. They have not significantly changed since VB3 - and that was back in the mid nineties. These were designed for use with Windows 3.1! You would be better off using the Open File and Save File dialogues which come with the Common Dialogues library.

As for the dlls for vb6 provided in windows 7, see http://msdn.microsoft.com/en-us/vstudio/ms788708.aspx
GetSetting is a VB6 call to the registry. Windows 7 on a 64bit machine moved the location of the registry for 32bit apps to something like WOW3264.

Related

How to change Windows folder permission with VB.NET? (System.UnauthorizedAccessException)

I am working on this small VB.NET application which needs to copy a couple files to a Windows folder but I am getting an access denied error; then if I go to the folder, right-click it and manually write the write permission to the folder everything will work fine.
However this application is going to be used by our employees in several machines of the network and mostly of them has not this level of "expertise" meaning that the process must happen smoothly and automatically and therefore the change of the permission should be done by the application itself.
I found a code snippet online which supposed to fix the problem but it is not working for me. I am getting a runtime error with the following message:
System.UnauthorizedAccessException: 'Attempted to perform an unauthorized operation.'
And this is the code I am using:
Dim folder As String = "C:\Program Files (x86)\MyCompany\MyApp"
Dim sid As SecurityIdentifier = New SecurityIdentifier(WellKnownSidType.AuthenticatedUserSid, Nothing)
Dim writerule As FileSystemAccessRule = New FileSystemAccessRule(sid, FileSystemRights.Write, AccessControlType.Allow)
Dim fsecurity As DirectorySecurity = Directory.GetAccessControl(folder)
fsecurity.AddAccessRule(writerule)
Directory.SetAccessControl(folder, fsecurity) 'the error happens here
The error happen exactly in the line where the permission setting try to apply. Any idea?
The solution is to level up the privileges of the application. Here it is how to force the program to do it automatically without the need of right-click it and choose "run as administrator" every time:
https://mobitek-system.com/blog/2020/06/how-to-run-vb-net-code-as-an-administrator/
😁

ASP (classic) call to VB6 DLL that calls to GDI+ works on IIS6 but not IIS7

On Windows Server 2003 32-bit, IIS 6.0 I currently have a working ASP classic page successfully using a VB6 DLL to render text as images using many varied fonts (the DLL references GDI+ to render a jpeg of the text in the specified font, etc.):
[working VBScript calling out to a VB6 DLL which calls to GDI+]
Set ig = Server.CreateObject("MyCo.ImageGenerator") 'the DLL
ret = ig.GenerateImage(text, font, size, path, color, italics, bold)
I need to transfer this site to a Windows 2008 or later server. On the new server, GDI+ has an error, specifically at this line in the VB6 DLL code:
lRes = GdipCreateBitmapFromHBITMAP(pict.Handle, 0, lBitmap) 'ret 2 (0 is success)
When I call the same DLL function (i.e. GenerateImage) from a Windows Forms App on the new server, it generates the image with no problem. I don't think it's a permissions issue because:
the target folder for generated images that the ASP VBScript directs the DLL to has full permissions for "Everyone" (for setup testing only) and
logging code in the DLL can write to the target directory
EDIT I (later) gave the Network Service user (the app pool account) read / read-execute permission without seeing a change in behavior (as suggested in a comment by #Lankymart).
I'm confused why the DLL works fine from a Windows Forms app call, but not from within IIS 7.
Hi IIS>Advanced Properties> Enable 32-Bit Application> is True check please and windows server x64 then dll register for C:\Windows\SysWOW64

Start Outlook 2016 (64 Bit) automatically minimised to Windows 10 (64 Bit) system tray - No active Explorer object found

I have an issue with an auto start of Outlook 2016 at boot/log on which is intended to start Outlook minimised to the Windows system tray, such that once invoked at Windows 10 launch mail will be collected by the mail account(s) (NB. All POP in this case.) whilst the program resides in the system tray remaining invisible until required by the user.
The .vbs script below does function as required but much of the time it introduces two unwelcome issues.
The Outlook icon in the System Tray displays a 'cog' overlay with the message "Another program is using Outlook. To disconnect programs and exit Outlook, click the Outlook icon and then click Exit Now".
Attempts to open Outlook from the 'Open Outlook' context menu (right click Outlook icon in the tray) item causes a dialogue box to appear reporting "No active explorer object found". Clicking the "OK" option in response launches Outlook (though issue 1 - cog overlay) remains.
Neither issue is present when Outlook is started normally from the desktop so it would appear that the .vbs script is in someway responsible. I have used this script successfully (see also below: https://superuser.com/questions/467809/start-outlook-automatically-in-tray) in the past both as a startup menu shortcut and a hkcu 'run' registry entry.
Can anyone suggest the cause or alternately a suitable code revision to achieve correct function? In case it is significant, Windows 10 is 64 bit Pro and the version of Office (including Outlook) installed is also 64 bit.
This is the code invoked by the .vbs script:
OPTION EXPLICIT
OPTION EXPLICIT
CONST PATH_TO_OUTLOOK = """C:\Program Files\Microsoft Office\Office16\OUTLOOK.EXE"""
CONST SHOW_MAXIMIZED = 3
CONST MINIMIZE = 1
DIM shell, outlook
SET shell = WScript.CreateObject("WScript.Shell")
' Open Outlook
shell.Run PATH_TO_OUTLOOK, SHOW_MAXIMIZED, FALSE
ON ERROR RESUME NEXT
' Grab a handle to the Outlook Application and minimize
SET outlook = WScript.CreateObject("Outlook.Application")
WScript.Sleep(100)
outlook.ActiveExplorer.WindowState = SHOW_MAXIMIZED
' Loop on error to account for slow startup in which case the
' process and/or the main Outlook window is not available
WHILE Err.Number <> 0
Err.Clear
WScript.Sleep(100)
SET outlook = NOTHING
SET outlook = WScript.CreateObject("Outlook.Application")
outlook.ActiveExplorer.WindowState = MINIMIZE
WEND
ON ERROR GOTO 0
SET outlook = NOTHING
SET shell = NOTHING
Having spent a number of hours on this issue over the weekend I thought that I had resolved the issues and got everything functioning as intended.
Working from similar samples of code I compiled a new script (see below) which I applied both as a shortcut in the Startup folder and also as an entry into the 'run' branch of the HKCU registry.
Now for the issue! Testing the script on two separate Windows 10 Pro (both 64 Bit architecture) systems both with Outlook 2016 64 Bit installed as part of a 64 Bit Office suite I found that whereas on one system the script runs flawlessly on the other I receive the following runtime error:
Script: D:\Neil's Files\Neil's Filing Cabinet\Neil's Emails\Start Outlook Minimised to Tray\Start Outlook 2016 Minimised To Tray.vbs
Line: 11
Char: 5
Error: ActiveX component can't create object: 'GetObject'
Code: 800A01AD
Source: Microsoft VBScript runtime error
This has me perplexed as the script file and it's related shortcut are both physical copies of each other given that the revised script below contains no path references (as these are handled directly by the code in respect of Outlook.exe) which are identified by the placement of either the shortcut or as the data element of the registry string whichever format is used.
The Systems do have some differences however and for comparative purposes I will summarise those I feel to be relevant here:
System 1: (The problem system) is an X58 Asus P6T7, Intel i720 mature PC with many programs installed and specifically the Outlook 2016 has the same 12 addins installed but in addition has two related programs which launch at boot, the enterprise editions of 4team's Sync2 for Microsoft Outlook and Safe PST Backup. The boot times are quite lengthy (but acceptable) as is the Outlook Startup with it's various addins.
System 2: Is a current generation Asus X99-Deluxe, i7 5930 new build pc with little installed as yet save MS Office, Adobe CC and some utilities.
In the case of System 1, Outlook auto-starts as intended however during it's loading splash screen (whilst it is loading up the addins) the runtime error is displayed although Outlook continues to open fully but fails to minimise.....
This suggests to me that the faulting code is the section which activates the window however the above error message refers to "ActiveX component can't create object: 'GetObject'" which suggests instead an issue with the code line "Set OLObj = GetObject("","Outlook.Application")"??
Hopefully somebody can test the code on a similar setup and report back? Or alternately, give me a pointer as to what is going on and how I might resolve it. I would of course also welcome any suggested improvements to the code!
** Quick Update ** Now tested on HP Elitebook 8440P Laptop - Windows 10 Pro 64 Bit with Office 64 Bit + same 12 Outlook Addons - Functions as intended.....
** Further Update ** Tested on a second HP Elitebook 8440P Laptop - Windows 10 Pro 64 Bit with Office 64 Bit + same 12 Outlook Addons - Above RunTime error experienced once again.......struggling to comprehend why these results are occurring?? Any thoughts anybody???
The code below is offered "as is" for the benefit of anyone else seeking the same Outlook auto start criteria. The testing with System 2 indicates that it works so I hope others enjoy similar success until the outstanding issues are sorted.
NB: To adjust the Outlook Launch Window Size (during its 10 second pause prior to automated minimising) to reflect personal preferences change the numeric value in the following line of code:
WshShell.Run "OUTLOOK.EXE" , 3, false
For a maximised window size change the value to 3 For a restored window size change the value to 2
OPTION EXPLICIT
Dim WshShell
Dim OLObj
Set WshShell = WScript. CreateObject ( "Wscript.Shell" )
'Open Outlook: Note that inspite of the launch options, it will open the program in a normal window.
'The file location path is not necessary as Windows 10 correctly identifies Outlook's location.
WshShell.Run "OUTLOOK.EXE" , 3, false
'This will mimimise it to the system tray after a 10 second pause to allow for mail collection on Outlook launch.
WScript.Sleep (10000)
Set OLObj = GetObject("","Outlook.Application")
'Activates the window
OLObj.ActiveExplorer.Activate
'Sends the command to minimise
OLObj.ActiveExplorer.WindowState = 1
'Outlook does not immediately minimise to the system tray so that 'Send/Receive' can initiate mail collection.
Thanks to jrv from Microsoft's "The Scripting Guys" forum who kindly offered a revised (simplified) code which is below. I can report that as with the original code it works flawlessly on the same 2 systems as before, whilst faulting once more on the other two......very much perplexed!!
The Runtime Error:
Script: D:\Neil's Files\Neil's Filing Cabinet\Neil's Emails\Start Outlook Minimised to Tray\Start Outlook 2016 Minimised To Tray.vbs
Line: 3
Char: 5
Error: ActiveX component can't create object: 'Outlook.Application'
Code: 800A01AD
Source: Microsoft VBScript runtime error
The revised code:
Set WshShell = CreateObject ( "Wscript.Shell" )
WshShell.Run "OUTLOOK.EXE" , 3, False
Set ol = CreateObject("Outlook.Application")
ol.ActiveExplorer.Activate
ol.ActiveExplorer.WindowState = 1
You can use like file *.reg:
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run]
"Outlook"="C:\\Windows\\system32\\cmd.exe /c \"start \"\" /min \"C:\\Program Files\\Microsoft Office\\Office16\\OUTLOOK.EXE\"\""
[HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\Outlook\Preferences]
"MinToTray"=dword:00000001
I have an answer that works well with Office 2013 on Windows 7, and I hope it works for you too.
Essentially, this solution bypasses the issue with trying to force Outlook to minimize after loading. Instead, it relies on using a shortcut that's already configured to load the program in a minimized state.
Copy a shortcut to Outlook into the directory containing your script.
Right click the shortcut and open Properties.
In the Shortcut tab, change the Run mode to Minimized. Press OK.
Then, all you need to do in your VBScript file is to execute the shortcut like so:
Dim sh : Set sh = CreateObject("WScript.Shell")
sh.run "Outlook.lnk"
Note that because this solution uses a shortcut, you could potentially remove the VBScript part entirely by putting the shortcut into the All Users Startup folder.
It's me again! I have an answer that should bypass any issues with VBScript by using third-party software, DisplayFusion. I don't know how you'll feel about that, but I tested it and it works over here. I use this at home and at work to manage multiple monitors and various other things. It may even help solve problems with other programs you use and render various VBS hacks redundant.
In your case, there is a feature called 'Triggers'. Note that while there is a free version of DF, you'll have to activate a 30 day trial for the Pro version to use Triggers, and after that, it's up to you to decide if it's worth your while.
Firstly, after installing DF, you'll want to open up its settings window (right-click desktop and go to DisplayFusion > Settings).
Go to the Triggers tab and click Add.
Set up the trigger for when a window is created. Tell the trigger to activate only once per process ID so it won't also try to minimize subsequent windows, such as when composing a new email. Find the path to your outlook.exe. Then, add an action on the right-hand side to minimize the window.
Click OK twice and then see if it works by loading Outlook. For me, the splash screen appears as normal, then the main window is minimized as soon as it appears.
DF runs as a system service with admin privileges and has been tested with tonnes of software packages, so if this method also fails for you, it could indicate bigger issues with your system/Office configuration.

VB script fails when migrated to W7

I'm in the process of migrating a classic ASP site on an old 32bit XP server to a w7 64 bit. The application works fine where it is currently hosted.
When migrated, I get errors in the global.asa file:
Sub Session_OnStart
'works fine
Set Session("GaoAppEnv")=Server.CreateObject("GaoCommon.AppEnv.1")
'error
Set Session("GaoSession")=Session("GaoAppEnv").CreateSession("file.tps")
...
With the error:
Gao Subsystem error '80020009'
Unknown Exception
I tried to add some error catching code into the vb script around the problem area, but when I try to do WScript.Echo I get yet another error "Object required: 'WScript'"
I've added the registry settings for GaoCommon.AppEnv.1 via DLL, but file.tps seems to be only be a path in the registry to the file itself, and looks to be XML and not what I've seen for a tps filetype online.
It looks as though I've missed something in the migration over, any thoughts?
UPDATE- Things I've already done/checked:
App pool is 32bit
Registry has been updated with both file.tps and GaoCommon.AppEnv.1
First you will need to ensure your ASP runs in a 32-bit Application Pool on the IIS Server for backward compatibility.
Launch Internet Information Services (IIS) Manager.
In the Connections pane, click "Application Pools".
Highlight the application pool for your application, then click "Advanced Settings..." in the Actions pane.
In the "Advanced Settings" dialog, specify True for "Enable 32-Bit Applications".
Click OK to close the "Advanced Settings" dialog.
WScript.Echo is only valid for VBScript under WSH (i.e. scripts executed locally on the server via wscript.exe or cscript.exe). To debug in ASP, you may use Response.Write instead.

Issues while converting a windows app to windows service

I created a monitoring utility that checks cpu, ram, drive space stats and emails if the usage goes above set threshold. It works great in the system tray but I realized that the exe will stop when I log out of windows server. That led me to believe that I needed to create a windows service. I would like to use the existing GUI Form to save data to application settings and use those settings in windows service. Here are the steps I took so far,
Added a Windows Service class.
Modified the original code to get rid of any interactive items that were related to GUI Form.
Added the code to this class.
Added a Service installer.
Added this code to it-->
public ProjectInstaller()
{
InitializeComponent();
ServiceProcessInstaller serviceProcessInstaller = new ServiceProcessInstaller();
ServiceInstaller serviceInstaller = new ServiceInstaller();
serviceProcessInstaller.Account = ServiceAccount.LocalSystem;
serviceProcessInstaller.Username = null;
serviceProcessInstaller.Password = null;
serviceInstaller.StartType = ServiceStartMode.Automatic;
serviceInstaller.ServiceName = "Server Monitoring";
this.Installers.Add(serviceProcessInstaller);
this.Installers.Add(serviceInstaller);
}
Change Start up object to Utility.Program.
When I try installing this through installUtil I get this error
System.IO.FileNotFoundException: Could not load file or assembly 'file:///C:\Use
rs\AdminUser\Desktop\Temp\Server' or one of its dependencies. The system cannot
find the file specified..
Thanks!
If you are saving these application settings into a file that is in the same directory as the Windows service, that is going to be your problem. All Windows Services are run in the C:/Windows directory (or a sub-directory in there) so when you access files you will need to do one of two things:
Change the executing directory
You can change the 'current directory' for the executing app back to the folder that contains the exe with the following line of code:
System.IO.Directory.SetCurrentDirectory(System.AppDomain.CurrentDomain.BaseDirectory);
This will make all relative files become relative to the executable location once again.
Make all file request full paths
This one is easier for some files than others. System files are the hardest. So if you are trying to get to a .config file, that's going to be a nightmare.

Resources