中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-08-02 10:11
48,037 topics / 350,122 posts / today 0 new / 48,250 members
DOS批处理 & 脚本技术(批处理室) » [Solved][vbs] How to assign a value containing ' to a variable
Printable Version  1,250 / 11
Floor1 bapala Posted 2006-11-08 05:31
初级用户 Posts 11 Credits 28
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 ]
Floor2 lxmxn Posted 2006-11-08 05:47
版主 Posts 4,938 Credits 11,386
Floor3 electronixtar Posted 2006-11-08 06:12
铂金会员 Posts 2,672 Credits 7,493
What does this have to do with vbs?
Floor4 lxmxn Posted 2006-11-08 06:43
版主 Posts 4,938 Credits 11,386

  electronixtar, why don't you write out a VBS assignment~ hehe~
Floor5 electronixtar Posted 2006-11-08 07:04
铂金会员 Posts 2,672 Credits 7,493
strcmd='notepad.exe'

Didn't understand what the OP meant. Just wrote one blindly.
Floor6 zerocq Posted 2006-11-08 07:07
中级用户 Posts 196 Credits 458
Floor7 bapala Posted 2006-11-09 04:23
初级用户 Posts 11 Credits 28
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.
Floor8 zerocq Posted 2006-11-09 07:07
中级用户 Posts 196 Credits 458
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 '
Floor9 electronixtar Posted 2006-11-09 07:40
铂金会员 Posts 2,672 Credits 7,493
Oh, that's what you mean. Too simple. msgbox "'" won't turn into a comment, right?

strcmd="'notepad.exe'"
Floor10 3742668 Posted 2006-11-09 08:06
荣誉版主 Posts 718 Credits 2,013
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:


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:
:
:
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.
Floor11 bapala Posted 2006-11-09 08:11
初级用户 Posts 11 Credits 28
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:
Floor12 3742668 Posted 2006-11-09 08:33
荣誉版主 Posts 718 Credits 2,013
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.
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023