China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-02 11:23
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Solved][vbs] How to assign a value containing ' to a variable View 1,252 Replies 11
Original Poster Posted 2006-11-08 05:31 ·  中国 江苏 苏州 联通
初级用户
Credits 28
Posts 11
Joined 2006-07-11 21:39
20-year member
UID 58408
Status Offline
For example, the variable name is: strcmd, and the value needs to be 'notepad.exe', not "'notepad.exe'". How can this be done? I looked through a lot of help files and couldn't find it, very depressed. If any expert knows, thanks.

[ Last edited by bapala on 2006-11-9 at 08:21 AM ]
Floor 2 Posted 2006-11-08 05:47 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
20-year member
UID 59080
Status Offline
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
redtek +2 2006-11-08 06:13
Floor 3 Posted 2006-11-08 06:12 ·  中国 四川 成都 教育网
铂金会员
★★★★
Credits 7,493
Posts 2,672
Joined 2005-09-02 00:00
20-year member
UID 42173
Gender Male
Status Offline
What does this have to do with vbs?

C:\>BLOG http://initiative.yo2.cn/
C:\>hh.exe ntcmds.chm::/ntcmds.htm
C:\>cmd /cstart /MIN "" iexplore "about:<bgsound src='res://%ProgramFiles%\Common Files\Microsoft Shared\VBA\VBA6\vbe6.dll/10/5432'>"
Floor 4 Posted 2006-11-08 06:43 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
20-year member
UID 59080
Status Offline

  electronixtar, why don't you write out a VBS assignment~ hehe~
Floor 5 Posted 2006-11-08 07:04 ·  中国 四川 成都 教育网
铂金会员
★★★★
Credits 7,493
Posts 2,672
Joined 2005-09-02 00:00
20-year member
UID 42173
Gender Male
Status Offline
strcmd='notepad.exe'

Didn't understand what the OP meant. Just wrote one blindly.

C:\>BLOG http://initiative.yo2.cn/
C:\>hh.exe ntcmds.chm::/ntcmds.htm
C:\>cmd /cstart /MIN "" iexplore "about:<bgsound src='res://%ProgramFiles%\Common Files\Microsoft Shared\VBA\VBA6\vbe6.dll/10/5432'>"
Floor 6 Posted 2006-11-08 07:07 ·  中国 浙江 温州 电信
中级用户
★★
Credits 458
Posts 196
Joined 2006-10-05 12:04
19-year member
UID 64614
Status Offline
Floor 7 Posted 2006-11-09 04:23
初级用户
Credits 28
Posts 11
Joined 2006-07-11 21:39
20-year member
UID 58408
Status Offline
What the boss means is to periodically kill a process, for example notepad.exe. Since the boss hasn't decided on the name yet, I need to use strcmd here in place of the process name, so I want the value of strcmd to be 'notepad.exe', not "'notepad.exe'". If I write it like strcmd='notepad.exe', VBS treats it as a comment and it becomes strcmd=
Originally posted by electronixtar at 2006-11-8 07:04:
strcmd='notepad.exe'

Didn't understand what the OP meant. Just wrote one blindly.
Floor 8 Posted 2006-11-09 07:07 ·  中国 浙江 温州 电信
中级用户
★★
Credits 458
Posts 196
Joined 2006-10-05 12:04
19-year member
UID 64614
Status Offline
Originally posted by bapala at 2006-11-9 04:23:
What the boss means is to periodically kill a process, for example notepad.exe. Since the boss hasn't decided on the name yet, I need to use strcmd here in place of the process name, so I want the value of strcmd to be 'notepad.exe'@...


It's exactly because adding a ' turns it into a comment, so you need to add a " outside the '
Floor 9 Posted 2006-11-09 07:40 ·  中国 四川 成都 教育网
铂金会员
★★★★
Credits 7,493
Posts 2,672
Joined 2005-09-02 00:00
20-year member
UID 42173
Gender Male
Status Offline
Oh, that's what you mean. Too simple. msgbox "'" won't turn into a comment, right?

strcmd="'notepad.exe'"

C:\>BLOG http://initiative.yo2.cn/
C:\>hh.exe ntcmds.chm::/ntcmds.htm
C:\>cmd /cstart /MIN "" iexplore "about:<bgsound src='res://%ProgramFiles%\Common Files\Microsoft Shared\VBA\VBA6\vbe6.dll/10/5432'>"
Floor 10 Posted 2006-11-09 08:06 ·  中国 湖北 荆门 电信
荣誉版主
★★★
Credits 2,013
Posts 718
Joined 2006-02-18 07:07
20-year member
UID 50550
Status Offline
Re bapala:
As the several posters above said, a ' wrapped in quotation marks will not be treated as a comment.
Also, if you run into characters that seem hard to handle, you can try using the chr function instead. For example:
strCmd = Chr(39) & "notepad.exe" & chr(39)


As for terminating a process, there is no rule saying you must add single quotes on both sides of the process name. I think you're probably using the select xxx from win32_process where .... statement in the execquery method. I suggest you change it to one of the following:
:

strProcess = "notepad.exe"
for each x in getobject("winmgmts:win32_process").instances_
if ucase(x.name) = ucase(strProcess) then x.Terminate
next

:

strProcess = "notepad.exe"
for each x in getobject("winmgmts:").instancesof("win32_process")
if ucase(x.name) = ucase(strProcess) then x.Terminate
next

Or you can use the wscript.arguments object to obtain the name of the process to be terminated through parameters.

None of the above code has been tested; if there are errors, please debug and modify it yourself.
Floor 11 Posted 2006-11-09 08:11 ·  中国 江苏 苏州 电信
初级用户
Credits 28
Posts 11
Joined 2006-07-11 21:39
20-year member
UID 58408
Status Offline
Moderator expert, thank you. I was using it in an SQL statement, so I needed to use 'notepad.exe' and couldn't use "'notepad.exe'" or chr() & "notepad.exe" & chr(). But the other two methods the moderator gave are workable.
Also thanks to all the brothers above!
Originally posted by 3742668 at 2006-11-9 08:06:
Re bapala:
As the several posters above said, a ' wrapped in quotation marks will not be treated as a comment.
Also, if you run into characters that seem hard to handle, you can try using the chr function instead. For example:
strCmd =  ... 


[ Last edited by bapala on 2006-11-9 at 08:15 AM ]
Floor 12 Posted 2006-11-09 08:33 ·  中国 湖北 荆门 电信
荣誉版主
★★★
Credits 2,013
Posts 718
Joined 2006-02-18 07:07
20-year member
UID 50550
Status Offline
I was using it in an SQL statement, so I needed to use 'notepad.exe' and couldn't use "'notepad.exe'" or chr() & "notepad.exe" & chr(). But the other two methods the moderator gave are workable.
Also thanks to all the brothers above!

1. That's not called SQL, it's called WQL. Although Microsoft officially says it is a subset of SQL, it is obvious that it differs from SQL in fairly clear ways.
2. I suggest you read more basic articles. From your reply, it's clear that your concept of variables is still not very clear, and you're not very familiar with VBS script syntax either. Otherwise you'd discover that even when using the execquery method, you still don't need to add ' on both sides when assigning a value to the variable.
Forum Jump: