|
Easy enough to solve. Use a Regular Expression to return the text inside the % characters, then just look that up in the environment variables and rebuilt the path using the returned values. It's mostly just simple string manipulation.
|
|
|
|
|
never thought about a regex. i pretty much suck when it comes to expressions, but i guess i'm not the only one.
any thoughts on what it might look like.
|
|
|
|
|
The RegEx expression might look something like:
%{1}(?'EnvName'\w{1,32})%{1}
This will capture the occurance of everything inside of a pair of % characters as a named capture group. Google for "RegEx.GetGroupNames" for an example of grabbing the text returned by the groups.
Oh, almost forgot. I use Expresso when it comes to Regular Expressions. It's an indispensible tool.
|
|
|
|
|
this is what i have so far
Dim regex As RegularExpressions.Regex
regex = New RegularExpressions.Regex("%{1}(?'EnvName'\w{1,32})%{1}")
Dim found As RegularExpressions.MatchCollection = regex.Matches(ProgramPath)
For Each aMatch As RegularExpressions.Match In found
Console.WriteLine(aMatch.ToString)
Console.WriteLine(Environment.GetEnvironmentVariable(aMatch.ToString.Replace("%", "")))
Next
which works like a champ
this "%windir%%programfiles%%systemroot%" for ProgramPath
gives me
%windir%
C:\WINDOWS
%programfiles%
C:\Program Files
%systemroot%
C:\WINDOWS
i am working on trying to get the regex to replace the %windir% with the GetEnvironmentVariable
but so far no luck. the input can be "%windir%\test"
most of the replace examples i find are for phone numbers and the like.
thank you again for your help.
|
|
|
|
|
Not sure if this is what you guys had in mind for final code but i hope this passes muster.
Dim regex As RegularExpressions.Regex
regex = New RegularExpressions.Regex("%{1}(?'EnvName'\w{1,32})%{1}")
Dim found As RegularExpressions.MatchCollection = regex.Matches(ProgramPath)
For Each aMatch As RegularExpressions.Match In found
myUpdateLog.AppendLine(ProgramPath)
ProgramPath = RegularExpressions.Regex.Replace(ProgramPath, aMatch.ToString, Environment.GetEnvironmentVariable(aMatch.ToString.Replace("%", "")))
myUpdateLog.AppendLine(ProgramPath)
Next
as a side note if anyone is interrested in an app for updating your programs let me know and i will share the code with you.
|
|
|
|
|
When I use the following code:
Private Sub addstart()
Dim Reg As Object
Set Reg = CreateObject("WScript.shell")
Reg.RegWrite "HKEY_CURRENT_USER\SOFTWARE\MICROSOFT\WINDOWS\CURRENTVERSION\RUN\" & App.EXEName, App.Path & "\" & App.EXEName & ".exe"
End Sub
Private Sub removeStart()
On Error Resume Next
Dim Reg As Object
Set Reg = CreateObject("WScript.shell")
Reg.RegDelete "HKEY_CURRENT_USER\SOFTWARE\MICROSOFT\WINDOWS\CURRENTVERSION\RUN\" & App.EXEName
End Sub
The program starts up fine at windows startup, but a dialog box pops up it says "you have changed the system configuration utility to make changes in the way Windows starts."
Is there a way to have your program automatically start without having that message pop up?
|
|
|
|
|
There's some other app that's putting that message up. It's not comming from Windows. Perhaps a virus scanner or some other startup monitoring software you have...
BTW: The entires in that registry key you're referring to are not run at Windows startup. They are run whenever a user logs into Windows at the console.
|
|
|
|
|
Hi there basicly im creating programe about customers in rent car office and i need to print the application with vb2008 by clicking on the printer button
Regrads,
|
|
|
|
|
Take a look at the Printer and PrintDocument classes on MSDN.
There is also a PrintPreview class, if you want to provide that functionality.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Hi Guys,
I have this weird problem in a VB6 application i am maintaining where an unexpected value is returned from addition of two doubles. One of those doubles is negative. Eg.
Dim tst As Double
Dim tst1 As Double
tst = -8.4
tst1 = 8.45
tst = tst + tst1
MsgBox tst
The Value of tst is 4.99999999999989E-02 when the MsgBox appears.
Anyone know whats going on here?
Thanks In Advance
|
|
|
|
|
For standard questions like this I have a standard answer:
The way floats/doubles are stored in binary makes it impossible to exactly represent
most values, especially the ones that seem like round numbers to humans thinking
using base ten.
So 4, 2, 1, 0.5, 3.5, 3.75 and many others are representable exactly (basically since
they all equal an integer divided by some power of 2); but 3.6 and 3.8 and an infinite
number of other values are not.
Now whatever float/double function you call, if it returns a float/double will suffer
from the same phenomenon. So the only way to really get "3.6" or "3.8" is by using a
function that not only rounds but returns a string. I trust there are some formatting
methods that do just that in every programming language; In .NET languages
ToString() should be one of them, given an appropriate format specifier.
If you want to know much more about this topic, here it is:
http://docs.sun.com/source/806-3568/ncg_goldberg.html
BTW: to circumvent the floating-point rounding problem, especially for monetary
numbers, they introduced the "decimal" data type (which basically stores decimal
digits).
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Cheers Luc,
I Knew it was something simple just could not put my finger on it, i found the following code will work:
Dim tst As Double
Dim tst1 As Double
tst = -8.4
tst1 = 8.45
tst = tst + tst1
<big>tst = Round(tst, 2)</big>
MsgBox tst
|
|
|
|
|
Hello,
I have a task that needs to be executed many times in a thread, so as to keep my GUI responsive. Right now I'm using the ThreadPool to accomplish the tasks, and it works perfectly. I get all the data I expect back from the threads, life's good.
When those tasks are finished, I then fire off another set of threads to accomplish another set of tasks, in the same fashion. The work method of these threads uses a call to RegistryKey.OpenRemoteBaseKey, which does exactly that, opens a remote registry key. The problem is: if the user running the application does not have permission to open the remote registry the call will throw an IOException, but I expect this behaviour because the user does not have permission to do it. However, the call itself can take FOREVER.
I wrote the application initially to use delegate methods and used the WaitHandle.WaitOne() method on AutoResetEvents in a state object I passed to each delegate. I tried the WaitOne method using a timeout, which worked fine until I realized that even though the WaitOne timed out, the thread was still running. This is a problem because (from what I understand) processes are only given a certain number of ThreadPool threads and, once used, they must be finished in order to be released back to the threadpool. In my work method, I also have a variable that can be signalled when the thread should be stopped, but that (obviously) only works on code that I've written.
So, my question is, how can I cancel a thread that's stuck on a .NET method? Is there some sort of garbage collection method I can call if I give it a handle? There has to be a way.
I've searched Google, MSDN and everywhere in between for solutions to this, but no one has an answer.
|
|
|
|
|
Brandon D. Legault wrote: how can I cancel a thread that's stuck on a .NET method?
You can't. You don't have any access to the managed thread pool threads themselves. If it's that critical, you'll have to implement your own threads to have greater control.
|
|
|
|
|
I apologize, but I really can't accept that. There has to be a way to do it.
I've tried using my own threads (by my own threads I assume you mean just a managed thread?) but I've read many many times that Thread.Abort is frowned upon, bad design etc... , also, it doesn't actually cancel the thread, it only flags it for cancellation, and waits for an appropriate time to cancel it.
OpenRemoteBaseKey isn't the only .NET method that works this way. ManagementScope.Connect(), which I also use to retrieve information in this application (and need to be able to cancel as well), is written similarly in that you cannot cancel it once you start it.
Without being able to cancel them, I don't see any practical functionality in either of these two methods (or any other .NET methods that work like this). I shouldn't have to write my own wrapper around the native methods *shudder*, to expose a functionality that should be shipped with these methods in the first place.
|
|
|
|
|
OK. Since the ThreadPool threads are completely encapsulated and insulated from your code, have fun with it!
|
|
|
|
|
|
Hi,
ThreadPool threads have their limitations, threads have a IsThreadPoolThread property, and when true, there are a couple of things you can't do. if you're not happy with it, use something else:
- BackgroundWorker;
- regular Threads.
The best article ever on threads is here[^].
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
I have a project in vb.net2008. Having Forms only 8 and 2 classes and 1 module, and 1 Splash screen
& 1 crystal report ..
From the 8 forms, 4 forms I used Data Gridview class object & 3 forms Crystal report 1 for screen design.
But it's showing the memory size for whole project 417-MB, is it true? Is it nature of vb.net 2008?
Or I have virus?
And Publish-setup.exe is 452 kb only...
Is it normal behavior? or virus?
Thanks
|
|
|
|
|
It's just a Visual Studio thing.
My advice is free, and you may get what you paid for.
|
|
|
|
|
Dear VBscript experts,
I have the following requirement which can be done in VB script . I am new to this forum and
am sure i will learn a lot by your valuable hints .
requirements are
- the log file should be deleted if the files are older than 400 days
- the log files from the server should be kept in the backup folder for 185 days.
Script should check the following:
1. Check if a file c:\\emailmoniroing\\logs\EmailLogyymmdd.log exists where ‘yymmdd’ denotes today’s date If it does
not, create a new file.
2. For each file in the ‘c:\\emailmonitor\main’ folder, check file size.
3. If file size=0, then move the file from the 'c:\\Emailmonitoring\main' folder to the ‘ c:\\emailmonitoring\backup’
folder
4. If file size >0, then read/append contents of the file to c:\emailmonitor\logs\EmailLogyymmdd.log. Move the file
read from the
'c:\\Emailmonitoring\main' folder to the ‘ c:\\emailmonitoring\backup’ folder
5. Delete all files older than 'x'' months from the c:\\emailmonitoring\backup folder
6. Delete all EmailLogyymmdd.log files older than ‘x’ months from the folder ‘c:\\emailmonitoring\Logs’
Finally,
Set up a windows scheduler task to run the new script every 20 minutes or it can run continuously, sleep and wake up
every 5 minutes
Could you provide any sample script something to acheive the above. it will be very useful to meet our business needs.
Thanks in advance
regards
pannar
|
|
|
|
|
Option Explicit
' Variable declaritions
Dim fso, f, f1, fc,sf
Dim colSubfolders
Dim objSubfolder
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder("C:\poetic\logs\Emailmonitoring")
Set fc = f.Files
Set colSubfolders = f.Subfolders
For Each objSubfolder in colSubfolders
'Wscript.Echo objSubfolder.Name, objSubfolder.Size
If((objSubfolder.Name = "backup") Or (objSubfolder.Name = "logs"))Then
Set sf = objSubfolder.Files
'log files under backup folder should be deleted if the files are older than 400 days
For Each f1 in sf
If DateDiff("d", f1.DateLastModified, Now) > 1 Then
f1.Delete
End If
Next
End If
Next
Set colSubfolders = Nothing
Set sf = Nothing
Set fso = Nothing
Set f = Nothing
Set fc = Nothing
|
|
|
|
|
Hi All,
How can i rotate Label to 90° Angle.
Thanks
If you can think then I Can.
|
|
|
|
|
|
Here is an article on codeproject with another good control to do this <a href="http://www.codeproject.com/KB/miscctrl/customtext.aspx">Customized Text - Orientated Controls in C# - Part I (Label Control)</a>[<a href="http://www.codeproject.com/KB/miscctrl/customtext.aspx" target="_blank" title="New Window">^</a>]
I know it is c# but it could easily be translated into VB.NET using <a href="http://www.icsharpcode.net/OpenSource/SD/">Sharp Develop</a>[<a href="http://www.icsharpcode.net/OpenSource/SD/" target="_blank" title="New Window">^</a>] or similar.
If you have knowledge, let others light their candles at it.
Margaret Fuller (1810 - 1850)
www.JacksonSoft.co.uk
|
|
|
|